printWriter print2 Example
printWriter class print example. This example shows you how to use print method.
PrintWriter class print example.method generates array of characters in to the abstract pathname associated file as well as on console.method throws null pointer exception if null is passed.
Here is the code:-
/**
* @Program uses print method to print an array of characters
* in to the abstract pathname file;
* Print2.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Print2 {
public static void main(String args[]) throws IOException {
File file = new File("c:\bunty.txt");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
file)));
char[] array = { 'r', 'o', 's', 'e', 'i', 'n', 'd', 'i', 'a' };
out.print("char array: ");
out.print(array);
System.out.print("char array: ");
System.out.println(array);
out.checkError();
}
} |
Output:-
Result generated on console as well as in the file passed.
|