目录

abstract OutputStream getOutputStream()

描述 (Description)

java.lang.Process.getOutputStream()方法获取子进程的输出流。 对流的输出通过管道传输到此Process对象表示的流程的标准输入流中。

声明 (Declaration)

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

public abstract OutputStream getOutputStream()

参数 (Parameters)

NA

返回值 (Return Value)

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

异常 (Exception)

NA

例子 (Example)

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

package com.iowiki;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
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 output stream
         OutputStream out = p.getOutputStream();
         // close the output stream
         System.out.println("Closing the output stream...");
         out.close();
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Creating Process...
Closing the output stream...
↑回到顶部↑
WIKI教程 @2018