Java Format - Java Formatter(File file, String csn) Constructor








Syntax

Formatter(File file, String csn) constructor from Formatter has the following syntax.

public Formatter(File file,   String csn)   throws FileNotFoundException ,     UnsupportedEncodingException

Example

In the following code shows how to use Formatter.Formatter(File file, String csn) constructor.

// w  w w .  j a  v a 2s  .  c  om
import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Formatter;

public class Main {

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


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

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