Java.io.PrintWriter.printf Locale() 方法


Java.io.PrintWriter.printf Locale() 方法

package com.codingdict;



import java.io.*;

import java.util.Locale;



public class PrintWriterDemo {



   public static void main(String[] args) {

      String s = "Hello World";



      try {



         // create a new writer

         PrintWriter pw = new PrintWriter(System.out);



         // printf text with specified locale.

         // %s indicates a string will be placed there, which is s

         pw.printf(Locale.UK, "This is a %s program", s);



         // change line

         pw.println();



         // printf text with specified locale

         // %d indicates an integer will be placed there, which is 100

         pw.printf(Locale.UK, "This is a %s program with %d", s, 100);



         // flush the writer

         pw.flush();



      } catch (Exception ex) {

         ex.printStackTrace();

      }

   }

}