Formatter(OutputStream os, String csn) constructor from Formatter has the following syntax.
public Formatter(OutputStream os, String csn) throws UnsupportedEncodingException
In the following code shows how to use Formatter.Formatter(OutputStream os, String csn) constructor.
//from w w w .jav a2s . c o m import java.io.FileNotFoundException; import java.io.FileOutputStream; 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 FileOutputStream("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."); } }