PrintWriter print Example
PrintWriter class print example. This example shows you how to use print method.
PrintWriter class print example. public void print(boolean b) Prints a boolean value. The string produced by String.valueOf(boolean) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.
Here is the code
/**
* @ # Print1.java
* A class reprsenting use to print method
* of PrintWriter class in java.io package
* version 10 June 2008
* author Rose India
*/
import java.io.*;
public class Print1 {
public static void main(String args[]) throws Exception {
// Create a new instance of a PrintWriter object along with
// an underlying StringWriter object.
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
stringWriter.write("Checks its error state : ");
printWriter.print(printWriter.checkError());
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
Output
| Checks its error state : false |
|