当前位置: 技术问答>java相关
一个Runtime的问题~ 编译通过 为什么运行时出现java.io.IOException: CreateProcess: dir error=0问题?
来源: 互联网 发布时间:2015-07-12
本文导语: 我jdk用 runtime调用程序 源代码如下 import java.io.*; public class test { public static void main(String[] args)throws IOException { Runtime runtime = Runtime.getRuntime(); ...
我jdk用 runtime调用程序 源代码如下
import java.io.*;
public class test {
public static void main(String[] args)throws IOException {
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}
}
然后编译通过 却出现
---------- java ----------
java.io.IOException: CreateProcess: dir error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Runtime.java:152)
at test.main(Compiled Code)
Exception in thread "main" Normal Termination
Output completed (1 sec consumed).
这样错误,为什么? 哪位高手告诉我如何解决??
import java.io.*;
public class test {
public static void main(String[] args)throws IOException {
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}
}
然后编译通过 却出现
---------- java ----------
java.io.IOException: CreateProcess: dir error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Runtime.java:152)
at test.main(Compiled Code)
Exception in thread "main" Normal Termination
Output completed (1 sec consumed).
这样错误,为什么? 哪位高手告诉我如何解决??
|
对了 如果用
p = runtime.exec("format a:");
format.com 可有哦
也会出同样的错误,我是cjde3tec 的同学……
p = runtime.exec("format a:");
format.com 可有哦
也会出同样的错误,我是cjde3tec 的同学……
|
p = runtime.exec("format.com a:");
--- ZJQ
--- ZJQ
|
try{
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}catch(Exception e){}
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}catch(Exception e){}
|
try{
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}catch(Exception e){}
Runtime runtime = Runtime.getRuntime();
Process p;
p = runtime.exec("dir ");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String strTmp = "";
while((strTmp = br.readLine())!=null) {
System.out.println(strTmp);
}
}catch(Exception e){}