PrintWriter write Example
PrintWriter class write example. This example shows you how to use write method.
PrintWriter class write example. public void write(String s) Writes a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.
Here is the code
/**
* @ # Write4.java
* A class reprsenting use to write method
* of PrintWriter class in java.io package
* version 12 June 2008
* author Rose India
*/
import java.io.*;
public class Write4 {
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);
//Writes a String.
printWriter.write("RoseIndia");
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|