PrintStream CheckError() Example
Flushes the stream and checks its error state.
PrintStreamclass CheckError() method example. This example shows you how to use CheckError() method.This method Flushes the stream and checks its error state.
Here is the code:-
/**
* @Program that Flushes the stream and checks its error state.
* CheckError.java
* Author:-RoseIndia Team
* Date:-10-Jun-2008
*/
import java.io.*;
public class CheckError {
public static void main(String[] args) throws IOException {
String c = "Girish Tewari";
//Creating FileOutputStream object
FileOutputStream out = new FileOutputStream("/home/girish/Desktop/g/m.txt");
FileInputStream fin = new FileInputStream("/home/girish/Desktop/g/m.txt");
//Creating PrintStream object
PrintStream ps = new PrintStream(out);
//Appends the specified character sequence to this output stream.
ps.append(c,7,13);
//Flushes the stream and checks its error state.
System.out.println("Checks its error state:"+ps.checkError());
System.out.println("Append successfully");
System.out.print("String after Appending is :");
for (int i = 0; i < c.length(); i++) {
System.out.print((char) fin.read());
}
ps.close();
}
} |
Output of the Program
Checks its error state:false
Append successfully
String after Appending is :Tewari |
|