Java Process.getErrorStream()

Syntax

Process.getErrorStream() has the following syntax.

public abstract InputStream getErrorStream()

Example

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


//w ww .  ja v  a 2  s. co m

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 error stream of the process and print it
         InputStream error = p.getErrorStream();
         for (int i = 0; i < error.available(); i++) {
            System.out.println(error.read());
         }

         // wait for 10 seconds and then destroy the process
         Thread.sleep(10000);
         p.destroy();

      } catch (Exception ex) {
         ex.printStackTrace();
      }

   }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable