I want to run code compiled earlier. In any case, I compiled, no matter how to compile, but running the code is a problem.
My code.java
public class code{ public static void main(String[] args) { System.out.println("Hello, World"); } }
Then I compiled this code and code.class (in the D:// directory) was generated. Now I want to run this compiled file. My code is:
import java.io.IOException; import java.io.InputStream; public class compiler { public static void main(String[] args) { final String dosCommand = "cmd /c java code"; final String location = "D:\\"; try { final Process process = Runtime.getRuntime().exec( dosCommand + " " + location); final InputStream in = process.getInputStream(); int ch; while((ch = in.read()) != -1) { System.out.print((char)ch); } } catch (IOException e) { e.printStackTrace(); } } }
There is no error here, but this code does nothing. No cmd opened, nothing. Where am I mistaken? What should I do?
java cmd runtime
Gürkan Çatak
source share