Java I/O 学习笔记(6) 进程IO流

时间:2023-02-14 23:58:02
package files;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestStreamOfProcess {

	public static void main(String[] args) throws IOException {
//		Process process = new ProcessBuilder("java -version".split(" ")).start();
		Process process = Runtime.getRuntime().exec("java");
        BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String str = null;
        while ((str = br.readLine()) != null) {
			System.out.println(str);
		}
        
        BufferedReader brError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        str = null;
        while ((str = br.readLine()) != null) {
			System.out.println(brError);
		}
	}

}