請看一下下面這個程序,是執行系統的DIR命令出錯
如果是執行如打開記事本之來的命令對聯不會錯
請問這是什么原因?
該怎么解決?
謝謝回復!:
import java.io.*;
public class CmdExec
{
//public CmdExec(String cmdLine)
public CmdExec(String[] cmdLine)
{
try{
String line;
//System.out.println("Command starting...");
Process p=Runtime.getRuntime().exec(cmdLine);
//System.out.println("Copy Successfully!");
}
catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] arg){
String[] commands = new String[]{"command.com", "/c", "dir"};
//new CmdExec("command.com /k copy *.rar d:\\TT");//這個不能夠招執行
//new CmdExec("notepad.exe");//這個能夠執行
new CmdExec(commands);
}
}