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 Test1");
} catch (IOException e) {
e.printStackTrace();
}
}
}
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");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("invoked successfully");
}
}
問題是如果我在Eclipse中運行Test1_Exec,則不會創建Test1.txt並且不報告錯誤。但是如果我在命令窗口中鍵入「java Test1」,則會創建Test1.txt。 Test1_Exec.java和Test1.java位於同一個src文件夾中; Test1_Exec.class和Test1.class位於同一個bin文件夾中。那麼Eclipse有什麼問題?我的Eclipse版本是開普勒(20130614-0229)。代碼不在eclipse中運行,但在命令窗口中運行
可能會發生這樣的情況,即如果JAVA_HOME env變量包含空格,那麼它會使JAVA_HOME env變量混淆。 – darijan