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