Java Formatter ioException()方法与示例
格式化程序类ioException()方法
ioException()方法在java.util包中可用。
ioException()方法用于获取此Formatter的Appendableappend()方法最后抛出的IOException,否则返回null。
ioException()方法是一个非静态方法,可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
ioException()方法在不存在任何异常时不会引发异常。
语法:
public IOException ioException();
参数:
它不接受任何参数。
返回值:
此方法的返回类型为IOException,当它被附加对象抛出时,它将获得最后一个异常;否则,当不存在任何异常时,它将返回null。
示例
//Java程序是演示示例
// ioException()格式化程序的方法
import java.util.*;
public class IOExceptionOfFormatter {
public static void main(String[] args) {
//实例化一个StringBuffer和Formmatter对象
StringBuffer sb = new StringBuffer();
Formatter formatt = new Formatter(sb, Locale.UK);
//通过使用format()方法是格式化字符串
formatt.format("Hi %s !", "NHOOO");
//显示格式化的字符串
System.out.println(formatt);
//通过使用ioException()方法是
//抛出的最后一个异常
//这个格式化程序
System.out.println("formatt.ioException(): " + formatt.ioException());
}
}输出结果
Hi NHOOO ! formatt.ioException(): null