%uA0java.lang.Process.getInputStream()%uA0方法获取子进程的输入流。数据流获取由该Process对象表示的进程的标准输出流管道的数据。
声明
以下是java.lang.Process.getInputStream()方法的声明
public abstract InputStream getInputStream()
参数
-
NA
返回值
此方法返回输入流连接到子进程的正常输出。
异常
-
NA
例子
下面的例子显示lang.Process.getInputStream()方法的使用。
package com.yiibai 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...