Java.io.PrintWriter.setError() Method

Advertisements


Description

The java.io.PrintWriter.setError() method Indicates that an error has occurred.This method will cause subsequent invocations of checkError() to return true until clearError() is invoked.

Declaration

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

protected void setError()

Parameters

  • NA

Return Value

This method does not return a value.

Exception

  • NA

Example

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

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

      // set the error state
      pw.setError();

   }
}

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

HelloWorld



Advertisements
Advertisements