Java.lang.Process.getInputStream() 方法
描述
java.lang.Process.getInputStream() 方法获取子进程的输入流。 流从这个 Process 对象表示的进程的标准输出流中获取通过管道传输的数据。
声明
以下是 java.lang.Process.getInputStream() 方法的声明。
public abstract InputStream getInputStream()
参数
NA
返回值
该方法返回连接到子进程正常输出的输入流。
异常
NA
示例
下面的例子展示了 lang.Process.getInputStream() 方法的使用。
package com.tutorialspoint;
import java.io.InputStream;
public class ProcessDemo {
public static void main(String[] args) {
try {
// create a new process
System.out.println("Creating Process...");
Process p = Runtime.getRuntime().exec("notepad.exe");
// get the input stream of the process and print it
InputStream in = p.getInputStream();
for (int i = 0; i < in.available(); i++) {
System.out.println("" + in.read());
}
// wait for 10 seconds and then destroy the process
Thread.sleep(10000);
p.destroy();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Creating Process...

