Example usage for java.util Formatter Formatter

List of usage examples for java.util Formatter Formatter

Introduction

In this page you can find the example usage for java.util Formatter Formatter.

Prototype

public Formatter(OutputStream os, Charset charset, Locale l) 

Source Link

Document

Constructs a new formatter with the specified output stream, charset, and locale.

Usage

From source file:Main.java

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();//  www .j  av a2s  . c om
    System.out.println("Formatter Flushed.");
}

From source file:Main.java

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

    Formatter formatter = new Formatter(new File("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();/*from  w  ww  . jav  a 2 s.c  om*/
    System.out.println("Formatter Flushed.");
}

From source file:Main.java

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

    Formatter formatter = new Formatter(new FileOutputStream("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();/*from w ww  .j  a v  a  2s  .co  m*/
    System.out.println("Formatter Flushed.");
}