abstract InputStream getErrorStream()
描述 (Description)
java.lang.Process.getErrorStream()方法获取子进程的错误流。 该流获取从此Process对象表示的进程的错误输出流中传输的数据。
声明 (Declaration)
以下是java.lang.Process.getErrorStream()方法的声明
public abstract InputStream getErrorStream()
参数 (Parameters)
NA
返回值 (Return Value)
此方法返回连接到子进程的错误流的输入流。
异常 (Exception)
NA
例子 (Example)
以下示例显示了lang.Process.getErrorStream()方法的用法。
package com.iowiki;
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...