0
Test1_Exec.java有關類路徑中運行配置在Eclipse
import java.io.IOException;
public class Test1_Exec {
public static void main(String[] args) throws IOException {
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("java -cp bin Test1");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Test1.java:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test1 {
public static void main(String[] args)
{
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream("d:\\ppp\\Test1.txt");
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Test1_Exec.class和Test1.class都在bin文件夾下JavaTest(項目名稱) ,而代碼確實有效。但我想通過添加bin文件夾(right clikcing JavaTest(project name)->Run As->Run Configuration | Tab Classpath --- User Entries --- Advanced --- Add Folders)
替換代碼"Process p = run.exec("java -cp bin Test1")"
與"Process p = run.exec("java Test1")"
,那麼Test1.txt
不是由新代碼創建的。那麼問題在哪裏?