printWriter format1 Example
printWriter class format example. This example shows you how to use format method.
PrintWriter class format example.method returns a formatted string data in to the abstract pathname file. method throws null pointer exception if null is passed in whole format constructor.
Here is the code:-
/**
* @Program uses format method to return a formatted string
* in to the abstract pathname file;
* Format.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Format1 {
public static void main(String args[]) throws IOException {
PrintWriter out = new PrintWriter("c:\Desktop\Baadshah/7up.txt");
String str0 = "javajazzup programming magazine", str1 = "roseindia.net";
Object obj[] = { str0, str1 };
out.format(str0, null);
out.println("");
out.format(str1, obj);
out.close();
}
} |
Output of the program:-
Result is printed in to the associated pathname file not on program output console
javajazzup programming magazine
roseindia.net |
|