protected void setError()
描述 (Description)
java.io.PrintStream.setError()方法将流的错误状态设置为true。
声明 (Declaration)
以下是java.io.PrintStream.println()方法的声明。
protected void setError()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.io.PrintStream.setError()方法的用法。
package com.iowiki;
import java.io.*;
public class PrintStreamDemo extends PrintStream {
public PrintStreamDemo(OutputStream out) {
super(out);
}
public static void main(String[] args) {
byte c[] = {70, 71, 72, 73, 74, 75, 76};
// create printstream object
PrintStreamDemo ps = new PrintStreamDemo(System.out);
// write bytes 1-3
ps.write(c, 1, 3);
// flush the stream
ps.flush();
// set an internal error
ps.setError();
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
GHI