目录

abstract InputStream getInputStream()

描述 (Description)

java.lang.Process.getInputStream()方法获取子进程的输入流。 流获取从此Process对象表示的进程的标准输出流中传输的数据。

声明 (Declaration)

以下是java.lang.Process.getInputStream()方法的声明

public abstract InputStream getInputStream()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回连接到子进程的正常输出的输入流。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Process.getInputStream()方法的用法。

package com.iowiki;
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...
↑回到顶部↑
WIKI教程 @2018