printWriter format2 Example
printWriter format append 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;
* Format2.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.util.Locale;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
public class Format2 {
public static void main(String args[]) throws IOException {
// PrintWriter format(Locale l, String format, Object... args)
String str = "roseindia.net for java programmers";
File data = new File("c:\78up.txt");
PrintWriter out = new PrintWriter(data);
Locale l = new Locale(Locale.US.toString());
//
Object obj[] = { str };
// .format(Locale, String, Object[])
out.format(l, str, obj);
out.close();
}
} |
Output of the program:-
Result is printed in to the associated pathname file not on program output console
| roseindia.net for java programmers |
|