PrintWriter write Example
PrintWriter class write example. This example shows you how to use write method.
PrintWriter class write example. public void write(char[] buf) Writes an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.
Here is the code
/**
* @ # Write1.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 Write1 {
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);
String s = "RoseIndia";
char[] ch = s.toCharArray();
//Writes an array of characters.
printWriter.write(ch);
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|