Using the Exec () method of the runtime object, you can run other programs on the platform that produce a process object that represents a child process that is started by the Java program.
The Process class provides 3 methods for communicating a program to its child processes
InputStream Geterrorstream (): Gets the error stream for the child process.
InputStream Getinputsteeam (): Gets the input stream of the child process.
OutputStream Getoutputstream (): Gets the output stream of the child process.
Example: Reading output information from another process
PackageCom.chengxuyuanzhiliu;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader; Public classreadfromprocess { Public Static voidMain (string[] args)throwsIOException {Process P= Runtime.getruntime (). EXEC ("Javac"); //try () {}jdk7 new syntax, closes the stream in (), effect type in finally Br.close () Try(BufferedReader br =NewBufferedReader (NewInputStreamReader (P.geterrorstream ()))) {String Buff=NULL; while(Buff = Br.readline ())! =NULL) {System.out.println (buff); } } }}
Execution Result:
Similar to the output information example for other processes
Java Virtual machine reads and writes data from other processes--process objects