printWriter print6 Example
printWriter class print example. This example shows you how to use print method.
PrintWriter class print example.method print String passed inside the method constructor either through string variable or direct value and printing in the abstract pathname file and not on the output console.
Here is the code:-
/**
* @Program uses print method to print the String value
* passed inside the method constructor either directly
* or through the variable;
* Print6.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Print6 {
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)));
String str0 = new String("For get in touch with worlds happenings"),
str1 = "be a regular memeber of newstrackindia.com family";
// String values passed in print method
out.print(str0);
out.println("");
out.print(str1);
out.close();
}
} |
Output:-
Result is printed on the file specified and not on console
For get in touch with worlds happenings
be a regular memeber of newstrackindia.com family |
|