Java Formatter(String fileName) Constructor
Syntax
Formatter(String fileName) constructor from Formatter has the following syntax.
public Formatter(String fileName) throws FileNotFoundException
Example
In the following code shows how to use Formatter.Formatter(String fileName) constructor.
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Formatter;
/* w w w. java 2s . c o m*/
public class Main {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
Formatter formatter = new Formatter("generated/format.txt");
// format a new string
String name = "from java2s.com";
formatter.format("Hello %s !", name);
// print the formatted string
System.out.println(formatter);
// flush the formatter. Here it does nothing.
formatter.flush();
System.out.println("Formatter Flushed.");
}
}
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »