📌  相关文章
📜  Java中的 CharsetDecoder unmappableCharacterAction() 方法及示例

📅  最后修改于: 2022-05-13 01:55:45.533000             🧑  作者: Mango

Java中的 CharsetDecoder unmappableCharacterAction() 方法及示例

unmappableCharacterAction()方法是Java.nio.charset.CharsetDecoder 类的内置方法,它返回此解码器对不可映射字符错误的当前操作。

语法

public CodingErrorAction unmappableCharacterAction()

参数:该函数不接受任何参数。

返回值:该函数返回此解码器对不可映射字符错误的当前操作。

下面是上述函数的实现:

方案一:

// Java program to demonstrate
// the above function
  
import java.nio.charset.*;
import java.util.Iterator;
import java.util.Map;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Gets the charset
        Charset charset = Charset.forName("ISO-2022-CN");
  
        // Get the CharsetDecoder
        CharsetDecoder decoder = charset.newDecoder();
  
        // Prints the CharsetDecoder
        System.out.println("CharsetDecoder: " + decoder);
  
        System.out.println("Current action for "
                           + "unmappable-character errors: "
                           + decoder.unmappableCharacterAction());
    }
}
输出:
CharsetDecoder: sun.nio.cs.ext.ISO2022_CN$Decoder@232204a1
Current action for unmappable-character errors: REPORT

方案二:

// Java program to demonstrate
// the above function
  
import java.nio.charset.*;
import java.util.Iterator;
import java.util.Map;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Gets the charset
        Charset charset = Charset.forName("x-windows-949");
  
        // Get the CharsetDecoder
        CharsetDecoder decoder = charset.newDecoder();
  
        // Prints the CharsetDecoder
        System.out.println("CharsetDecoder: " + decoder);
  
        System.out.println("Current action for "
                           + "unmappable-character errors: "
                           + decoder.unmappableCharacterAction());
    }
}
输出:
CharsetDecoder: sun.nio.cs.ext.DoubleByte$Decoder@232204a1
Current action for unmappable-character errors: REPORT

参考: https://docs.oracle.com/javase/9/docs/api/ Java/nio/charset/CharsetDecoder.html#unmappableCharacterAction–