IOException ioException()
描述 (Description)
java.util.Formatter.ioException()方法返回此格式化程序的Appendable最后抛出的IOException。
如果目标的append()方法永远不会抛出IOException,则此方法将始终返回null。
声明 (Declaration)
以下是java.util.Formatter.ioException()方法的声明
public IOException ioException()
参数 (Parameters)
NA
返回值 (Return Value)
此方法返回Appendable抛出的最后一个异常,如果不存在此类异常,则返回null。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.Formatter.ioException()方法的用法。
package com.iowiki;
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 latest exception, which is null
System.out.println("" + formatter.ioException());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Hello World !
null