Java.lang.Process.getErrorStream() 方法
描述
java.lang.Process.getErrorStream() 方法获取子进程的错误流。 流从这个 Process 对象表示的进程的错误输出流中获取数据。
声明
以下是 java.lang.Process.getErrorStream() 方法的声明。
public abstract InputStream getErrorStream()
参数
NA
返回值
该方法返回连接到子进程错误流的输入流。
异常
NA
示例
下面的例子展示了 lang.Process.getErrorStream() 方法的使用。
package com.tutorialspoint;
import java.io.InputStream;
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 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();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Creating Process...

