
- Java.util 包類
- Java.util - 首頁
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util 包擴充套件
- Java.util - 介面
- Java.util - 異常
- Java.util - 列舉
- Java.util 有用資源
- Java.util - 有用資源
- Java.util - 討論
Java Formatter ioException() 方法
描述
Java Formatter ioException() 方法返回此格式化程式的 Appendable 最後丟擲的 IOException。
如果目標的 append() 方法從未丟擲 IOException,則此方法將始終返回 null。
宣告
以下是 java.util.Formatter.ioException() 方法的宣告
public IOException ioException()
引數
無
返回值
此方法返回 Appendable 最後丟擲的異常,如果不存在此類異常,則返回 null。
異常
無
檢查 US 本地化格式化程式物件的 IOException 示例
以下示例演示了 Java Formatter ioException() 方法的使用,用於在使用格式化程式時列印 Appendable 丟擲的 IOException。我們建立了一個帶有 StringBuffer 和 US 本地化的格式化程式物件。Formatter 用於使用 format() 方法列印字串。然後我們列印了 ioException 物件。在本例中,它列印為 null。
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()); formatter.close(); } }
輸出
讓我們編譯並執行以上程式,這將產生以下結果:
Hello World ! null
檢查德語本地化格式化程式物件的 IOException 示例
以下示例演示了 Java Formatter ioException() 方法的使用,用於在使用格式化程式時列印 Appendable 丟擲的 IOException。我們建立了一個帶有 StringBuffer 和德語本地化的格式化程式物件。Formatter 用於使用 format() 方法列印字串。然後我們列印了 ioException 物件。在本例中,它列印為 null。
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.GERMAN); // 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()); formatter.close(); } }
輸出
讓我們編譯並執行以上程式,這將產生以下結果:
Hello World ! null
檢查法語本地化格式化程式物件的 IOException 示例
以下示例演示了 Java Formatter ioException() 方法的使用,用於在使用格式化程式時列印 Appendable 丟擲的 IOException。我們建立了一個帶有 StringBuffer 和法語本地化的格式化程式物件。Formatter 用於使用 format() 方法列印字串。然後我們列印了 ioException 物件。在本例中,它列印為 null。
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.FRENCH); // 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()); formatter.close(); } }
輸出
讓我們編譯並執行以上程式,這將產生以下結果:
Hello World ! null