Java IO Tutorial - Java PrintWriter.clearError()








Syntax

PrintWriter.clearError() has the following syntax.

protected void clearError()

Example

In the following code shows how to use PrintWriter.clearError() method.

//  w  w w  .ja v a2 s.c om

import java.io.*;

public class Main extends PrintWriter  {

   public Main(OutputStream out) {
      super(System.out);
   }

   public static void main(String[] args) {
      String s = "tutorial from java2s.com";

      
      Main pw = new Main(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();

   }
}

The code above generates the following result.