Test1_Exec.java
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();
}
}
}
测试1.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 都在 JavaTest(项目名称)下的 bin 文件夹中,并且代码确实有效。但是我想通过添加 bin 文件夹来替换代码"Process p = run.exec("java -cp bin Test1")"
,然后不是由新代码创建的。那么问题出在哪里?"Process p = run.exec("java Test1")"
( right clikcing JavaTest(project name)->Run As->Run Configuration | Tab Classpath --- User Entries --- Advanced --- Add Folders )
Test1.txt