當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.util.Formatter.ioException()用法及代碼示例


描述

這個java.util.Formatter.ioException()方法返回此格式化程序的 Appendable 最後一次拋出的 IOException。

如果目標的 append() 方法從不拋出 IOException,則此方法將始終返回 null。

聲明

以下是聲明java.util.Formatter.ioException()方法

public IOException ioException()

參數

NA

返回值

此方法返回 Appendable 拋出的最後一個異常,如果不存在此類異常,則返回 null。

異常

NA

示例

下麵的例子展示了 java.util.Formatter.ioException() 方法的用法。

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 latest exception, which is null
      System.out.println("" + formatter.ioException());
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果——

Hello World !
null

相關用法


注:本文由純淨天空篩選整理自 Java.util.Formatter.ioException() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。