PrintWriter println Example
PrintWriter class println example. This example shows you how to use println method.
PrintWriter class println example. public void println(Object x) Prints an Object and then terminates the line. This method calls at first String.valueOf(x) to get the printed object's string value, then behaves as though it invokes print(String) and then println().
Here is the code
/**
* @ # Println.java
* A class reprsenting use to println method
* of PrintWriter class in java.io package
* version 12 June 2008
* author Rose India
*/
import java.io.*;
import java.util.*;
public class Println8 {
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);
Set s = new TreeSet();
s.add(1);
s.add(2);
printWriter.print(new String("Rose "));
printWriter.println(s);
printWriter.print(new String("India"));
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|