Java.util.Formatter.out() 方法
描述
java.util.Formatter.out() 方法返回输出目标。
声明
以下是 java.util.Formatter.out() 方法的声明
public Appendable out()
参数
NA
返回值
此方法返回输出的目标
异常
FormatterClosedException − 如果此格式化程序已通过调用其 close() 方法关闭
示例
下面的例子展示了 java.util.Formatter.out() 方法的使用。
package com.tutorialspoint;
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 with default locale
System.out.println("" + formatter);
// print the output
System.out.println("" + formatter.out());
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World ! Hello World !

