Runtime rt = Runtime.getRuntime();
try { Process psPing = rt.exec("cmd.txt",null,new File("c:/"));
BufferedReader isPing = new BufferedReader(new InputStreamReader(psPing.getInputStream()));
String str = null;
while((str = isPing.readLine())!= null){
System.out.println(str);
}
} catch(IOException ex){
ex.printStackTrace();
return;
}
这样读取c盘的文件为什么总是报createProcess错误
java.io.IOException: CreateProcess: cmd.txt error=2最好能提供个例子,谢谢大家了
try { Process psPing = rt.exec("cmd.txt",null,new File("c:/"));
BufferedReader isPing = new BufferedReader(new InputStreamReader(psPing.getInputStream()));
String str = null;
while((str = isPing.readLine())!= null){
System.out.println(str);
}
} catch(IOException ex){
ex.printStackTrace();
return;
}
这样读取c盘的文件为什么总是报createProcess错误
java.io.IOException: CreateProcess: cmd.txt error=2最好能提供个例子,谢谢大家了
注意系统的环境变量的path中设置了 %SystemRoot% 否则 系统找不到Notepad.exe 或者你直接把绝对路径写上
import java.io.*;
public class ExtRunTime
{
public ExtRunTime()
{
}
public void execute()
{
Runtime rt = Runtime.getRuntime();
try
{
Process psPing = rt.exec("notepad aa.txt ",null,new File("C:\\")); //rt.exec("c:\\notepad aa.txt ",null,new File("C:\\"));
// BufferedReader isPing = new BufferedReader(new InputStreamReader(psPing.getInputStream()));
// String str = null;
// while((str = isPing.readLine())!= null)
// {
// System.out.println(str);
// }
}
catch(IOException ex)
{
ex.printStackTrace();
return;
}
}
public static void main(String arg[])
{
ExtRunTime run = new ExtRunTime();
run.execute();
}
}
public class Test
{
public static void main(String[] args)
{
Runtime runtime = Runtime.getRuntime();
Process p =null;
try
{
p=runtime.exec("cmd /c start C:\\你的EXE路徑\\XX.EXE");
//下面是執行批處理的
//p=runtime.exec("cmd /c start R:\\WinAP\\MER\\Go-MER.BAT");
//p.waitFor();
}
catch(Exception e )
{
System.out.println(e.toString());
} }
}
Process psPing = rt.exec("cmd /E:ON /c start c:\\cmd.txt");
试试,你要是装了相应软件的话