Java.io.PrintWriter.checkError() Method

Advertisements


Description

The java.io.PrintWriter.checkError() method Flushes the stream if it's not closed and checks its error state.

Declaration

Following is the declaration for java.io.PrintWriter.checkError() method

public boolean checkError()

Parameters

  • NA

Return Value

This method returns true if the print stream has encountered an error, either on the underlying output stream or during a format conversion.

Exception

  • NA

Example

The following example shows the usage of java.io.PrintWriter.checkError() method.

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo {

   public static void main(String[] args) {
      String s = "Hello World ";

      // create a new stream at system
      PrintWriter pw = new PrintWriter(System.out);

      // append the sequence
      pw.append(s);

      // check if there is an error and flush
      System.out.println("" + pw.checkError());


   }
}

Let us compile and run the above program, this will produce the following result

Hello Worldfalse



Advertisements
Advertisements