Java.util.Formatter.close() 方法


Java.util.Formatter.close() 方法

package com.codingdict;

import java.util.Formatter;
import java.util.Locale;

public class FormatterDemo {
   public static void main(String[] args) {

      // create a new formatter
      StringBuffer buffer = new StringBuffer();
      Formatter formatter = new Formatter(buffer, Locale.US);

      // format a new string
      String name = "World";
      formatter.format("Hello %s !", name);

      // print the formatted string
      System.out.println("" + formatter);

      // close the formatter
      formatter.close();

      // attempt to access the formatter results in exception
      System.out.println("" + formatter);
   }
}