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

