printWriter write3 Example
printWriter class write example. This example shows you how to use write method.
PrintWriter class write example. .write() method in the program takes single character value in single quotes in its constructor and writes the result in the file specified and not on the console output.
Here is the code:-
/**
* @Program uses write method to write single character in to
* the file specified.
* Write3.java
* Author:-RoseIndia Team
* Date:-7-july-2008
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class Write3 {
public static void main(String args[]) throws IOException {
File witches = new File("c:\celina.doc");
PrintWriter out = new PrintWriter(witches);
out.write('1');
out.write('2');
out.write('3');
out.println("");
out.write('1');
out.write('2');
out.write('3');
out.checkError();
}
} |
Output of the program:-
method writes the results in file and not on console.
|