Java Data Type Tutorial - Java Process.getInputStream()








Syntax

Process.getInputStream() has the following syntax.

public abstract InputStream getInputStream()

Example

In the following code shows how to use Process.getInputStream() method.

/* www. ja  v a  2  s .  c om*/
import java.io.InputStream;

public class Main {

   public static void main(String[] args) {
      try {
         // create a new 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();
      }

   }
}