java—— 调用系统命令

时间:2023-12-28 19:44:20

调用所在环境的命令

链接:http://blog.csdn.net/yy6060/article/details/6311916

 1 import java.io.*;
2 class Exec{
3 public static void main(String []args)throws IOException{
4 //windows系统命令:cmd /c dir
5 String command = "cmd /c dir ";
6 //获取当前系统的环境。
7 Runtime rt = Runtime.getRuntime();
8 //执行
9 Process p = null;
10 p = rt.exec(command);
11 //获取执行后的数据
12 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
13 String msg = null;
14 //输出。
15 while((msg = br.readLine())!=null){
16 System.out.println(msg);
17 }
18 br.close();
19 }
20 }

java Runtime的exec方法实例

链接: http://blog.csdn.net/yy6060/article/details/6311920

Java Runtime.exec()注意事项

链接:http://blog.csdn.net/flying881114/article/details/6272472