本篇文章中主要是和大家讲述java如何实现操作dos命令,感兴趣的朋友卡伊了解一下。下面一起进入正文吧!
读取文件中的命令:
package com; import java.io.InputStream; public class cmd { public static void main(String[] args) { String path = "D:\\cmd.bat"; Runtime run = Runtime.getRuntime(); try { //run.exec("cmd /k shutdown -s -t 3600"); Process process = run.exec("cmd.exe /k start " + path); InputStream in = process.getInputStream(); while (in.read() != -1) { System.out.println(in.read()); } in.close(); process.waitFor(); } catch (Exception e) { e.printStackTrace(); } } }
运行结果如下:
相关学习推荐:java基础教程
The above is the detailed content of How to implement dos command operation in java. For more information, please follow other related articles on the PHP Chinese website!