當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java 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...

相關用法


注:本文由純淨天空篩選整理自 Java.lang.Process.getOutputStream() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。