Java.io.PrintStream.clearError() 方法



描述

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

宣告

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

protected void clearError()

引數

返回值

此方法不返回值。

異常

示例

以下示例演示了java.io.PrintStream.clearError() 方法的使用。

package com.tutorialspoint;

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();

      // clear the errors of this stream, if there are any
      ps.clearError();
   }
}

讓我們編譯並執行上述程式,這將產生以下結果:

GHI
java_io_printstream.htm
廣告