List of usage examples for java.util Formatter format
public Formatter format(String format, Object... args)
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer); // 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();/*w w w . j av a2s .co m*/ System.out.println("Formatter Flushed."); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string with default locale System.out.println(formatter + " " + formatter.locale()); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string with default locale System.out.println(formatter); System.out.println(formatter.locale()); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string with default locale System.out.println(formatter); // print the output System.out.println(formatter.out()); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string with default locale System.out.println(formatter); // print the formatter as a string System.out.println(formatter.toString()); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // 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 w w . j av a2s. co m*/ System.out.println("Formatter Flushed."); }
From source file:Main.java
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();/*w w w . ja v a 2s . com*/ System.out.println("Formatter Flushed."); }
From source file:Main.java
public static void main(String[] args) { StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer, Locale.US); // format a new string String name = "from java2s.com"; formatter.format("Hello %s !", name); // print the formatted string System.out.println(formatter); // close the formatter formatter.close();//from w w w .j a v a 2 s . com // attempt to access the formatter results in exception System.out.println(formatter); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Formatter fmtCon = new Formatter(System.out); Formatter fmtFile = new Formatter(new FileOutputStream("test.fmt")); fmtCon.format("a negative number: %(.2f\n\n", -123.34); fmtCon.format("%8s %8s\n", "Value", "Square"); for (int i = 1; i < 20; i++) fmtCon.format("%8d %8d\n", i, i * i); // write to the file. fmtFile.format("This is a negative number: %(.2f\n\n", -123.34); fmtFile.format("%8s %8s\n", "Value", "Square"); for (int i = 1; i < 20; i++) fmtFile.format("%8d %8d\n", i, i * i); fmtFile.close();//from www .j a v a2 s. c o m if (fmtFile.ioException() != null) { System.out.println("File I/O Error Occurred"); } }
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException { Formatter formatter = new Formatter("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();/*from w ww . java 2 s . c om*/ System.out.println("Formatter Flushed."); }