printWriter print4 Example
printWriter class print example. This example shows you how to use print method.
PrintWriter class print example.method generates integer numbers values in to the abstract pathname file as well as on the output console.
Here is the code:-
/**
* @Program uses print method to print a set of integer
* numbers values in to the abstract pathname file;
* Print4.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Print4 {
public static void main(String args[]) throws IOException {
File file = new File("c:\monky.txt");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
file)));
int i = 1, j = 2, k = 3, l = 4;
out.print(i + " ");
out.print(j + " ");
out.print(k + " ");
out.print(l + " ");
System.out.println(i + " " + j + " " + k + " " + l);
out.flush();
}
} |
Output of the program:-
This set of numbers is generated on both file and console
|