printWriter write1 Example
printWriter class write example. This example shows you how to use write method.
PrintWriter class write example. .write() method in the program takes char array variable passed in its constructor and writes the array value into the abstract pathname file as well as on the output console.
Here is the code:-
/**
* @Program uses write method to write an array of characters
* in to the abstract pathname file;
* Write1.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Write1 {
public static void main(String args[]) throws IOException {
File fairy = new File("c:\pharoes.txt");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
fairy)));
char[] write_array = { 'n', 'e', 'w', 's', 't', 'r', 'a', 'c', 'k',
'i', 'n', 'd', 'i', 'a' };
out.print("char array: ");
out.print(write_array);
System.out.print("char array: ");
System.out.println(write_array);
out.flush();
}
} |
Output of the program:-
Same result is generated on both, the file and the program output console
| char array: newstrackindia |
|