public class Test {
public static void main(String[] args) throws IOException {
try {
//String[] cmds = {"cmd.exe","/c"," dir","c:",">","d://aa.txt"};
// Process pro = Runtime.getRuntime().exec(cmds);
Process pro = Runtime.getRuntime().exec("cmd.exe /c dir c: > d://aa.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream(),"GBK"));
String msg = null;
while ((msg = br.readLine()) != null) {
System.out.println(msg);
}
} catch (IOException exception) {
}
}
}
执行完成之后 会在d://下面生成一个aa.txt文件 里面保存了 dir的结果 其中 > 是 重定向 意思是讲执行结果从定向到 d://aa.txt
希望对你有帮助
取消
评论