printWriter print5 Example
printWriter class print example. This example shows you how to use print method.
PrintWriter class print example.method print objects passed inside the method constructor in the abstract pathname file and not on the output console.
Here is the code:-
/**
* @Program uses print method to print the object
* passed inside the method constructor;
* Print5.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Print5 {
public static void main(String args[]) throws IOException {
File file = new File("/home/mahendra/Baadshah/penguine.txt");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
file)));
Integer in = new Integer(123);
String str = new String("get flavours of java technology at roseindia:");
// passing integer and string objects in print method
out.print(in);
out.println("");
out.print(str);
out.close();
}
} |
Output of the program:-
Result is generated inside the file and not on the console
123
get flavours of java technology at roseindia: |
|