If I want to execute a Java application programmatically and I am in the same directory of the file [NewFile] I can simply use this method
try {
String line;
Process p2 = Runtime.getRuntime().exec( "java NewFile" );
BufferedReader in = new BufferedReader(
new InputStreamReader(p2.getInputStream()) );
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
catch (Exception e) {
// ...
}
But the problem is when I'm not in the directory of the file [NewFile]. I tried Process p2 = Runtime.getRuntime().exec( "java /users/Documents/project/NewFile" ); but it's not working.
ProcessBuilder.Runtime.exec()should not be used.