protected void setError()
描述 (Description)
java.io.PrintWriter.setError()方法表示发生了错误。此方法将导致checkError()的后续调用返回true,直到调用clearError()为止。
声明 (Declaration)
以下是java.io.PrintWriter.setError()方法的声明。
protected void setError()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.io.PrintWriter.setError()方法的用法。
package com.iowiki;
import java.io.*;
public class PrintWriterDemo extends PrintWriter {
public PrintWriterDemo(OutputStream out) {
super(System.out);
}
public static void main(String[] args) {
String s = "Hello World";
// create a new writer
PrintWriterDemo pw = new PrintWriterDemo(System.out);
// write substrings
pw.write(s, 0, 5);
pw.write(s, 6, 5);
// flush the writer
pw.flush();
// set the error state
pw.setError();
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
HelloWorld