Java调用Windows的DOS命令的方法
这是一个使用java代码调用dos命令的实例,在这里我就不多说,直接上代码,代码如下:
importjava.io.*;
/**
* Java调用windows的DOS命令
* 实现调用Windows的ipconfig命令,然后将输出的信息通过IO流输出到控制台。
*/
publicclassRunWindowsCommand{
publicstaticvoidmain(String[]args){
InputStreamins=null;
String[]cmd=newString[]{"cmd.exe","/C","ipconfig"}; //命令
try{
Processprocess=Runtime.getRuntime().exec(cmd);
ins=process.getInputStream(); //获取执行cmd命令后的信息
BufferedReaderreader=newBufferedReader(newInputStreamReader(ins));
Stringline=null;
while((line=reader.readLine())!=null){
System.out.println(line); //输出
}
intexitValue=process.waitFor();
System.out.println("返回值:"+exitValue);
process.getOutputStream().close(); //不要忘记了一定要关
}catch(Exceptione){
e.printStackTrace();
}
}
}
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短