Java.io.PrintWriter.format String() 方法


Java.io.PrintWriter.format String() 方法

package com.codingdict;



import java.io.*;



public class PrintWriterDemo {



   public static void main(String[] args) {

      String s = "Hello World";



      try {



         // create a new writer

         PrintWriter pw = new PrintWriter(System.out);



         // format text with default locale

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

         pw.format("This is a %s program", s);



         // change line

         pw.println();



         // format text with default locale

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

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



         // flush the writer

         pw.flush();



      } catch (Exception ex) {

         ex.printStackTrace();

      }

   }

}