Java Format - Java Formatter(String fileName, String csn, Locale l) Constructor








Syntax

Formatter(String fileName, String csn, Locale l) constructor from Formatter has the following syntax.

public Formatter(String fileName,   String csn,   Locale l)   throws FileNotFoundException ,     UnsupportedEncodingException

Example

In the following code shows how to use Formatter.Formatter(String fileName, String csn, Locale l) constructor.

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Formatter;
import java.util.Locale;
/*from  ww  w  . ja va  2 s. c  o m*/
public class Main {

   public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {


      Formatter formatter = new Formatter("generated/format.txt","ASCII",Locale.getDefault());

      // 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.");
   }
}