Java.io.PrintWriter.clearError() 方法



描述

java.io.PrintWriter.clearError() 方法清除此流的錯誤狀態。此方法將導致後續呼叫 checkError() 返回 false,直到另一個寫入操作失敗並呼叫 setError()。

宣告

以下是 java.io.PrintWriter.clearError() 方法的宣告。

protected void clearError()

引數

返回值

此方法不返回值。

異常

示例

以下示例演示了 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
java_io_printwriter.htm
廣告