码迷,mamicode.com
首页 > 编程语言 > 详细

Java代码中执行Linux命令,亲测可用

时间:2015-07-28 12:54:51      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

前提需要知道怎么在linux怎么新建java文件和怎么编译,否则请先学其他知识!!

import java.io.*;
public class Test{

public static void main(String[] args) throws Exception{
try{
Process process=Runtime.getRuntime().exec("ls ./");
InputStreamReader reader = new InputStreamReader(process.getInputStream());
LineNumberReader line = new LineNumberReader(reader);
String str;
while((str=line.readLine())!=null){
System.out.println(str);
}

}catch (Exception e){
e.printStackTrace();
}

System.out.println("done !!!");
}

Java代码中执行Linux命令,亲测可用

标签:

原文地址:http://www.cnblogs.com/ning-blogs/p/4682310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!