PrintWriter checkError Example
PrintWriter class checkError example. This example shows you how to use checkError method.
PrintWriter class checkError example. public boolean checkError() Flushes the stream if it's not closed and checks its error state.
Here is the code
/**
* @ # CheckError.java
* A class reprsenting use to CheckError method
* of PrintWriter class in java.io package
* version 10 June 2008
* author Rose India
*/
import java.io.*;
public class CheckError {
public static void main(String args[]) throws Exception {
// Create a new instance of a PrintWriter object along with
// an underlying StringWriter object.
String s = new String("Roseindia");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
//Write a string.
stringWriter.write(s);
// Appends a String into the writer.
printWriter.append(".Net....", 0, 4);
System.out.println(stringWriter.getBuffer());
if (printWriter.checkError()) {
System.out.println("Error ....");
}
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|