Java.io.PrintWriter.clearError() 方法
描述
java.io.PrintWriter.clearError() 方法清除此流的错误状态。 此方法将导致后续调用 checkError() 返回 false,直到另一个写入操作失败并调用 setError()。
声明
以下是 java.io.PrintWriter.clearError() 方法的声明。
protected void clearError()
参数
NA
返回值
此方法不返回值。
异常
NA
示例
下面的例子展示了 java.io.PrintWriter.clearError() 方法的使用。
package com.tutorialspoint;
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();
// clear the errors, if there are any
pw.clearError();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
HelloWorld

