当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java CharsetDecoder unmappableCharacterAction()用法及代码示例


unmappableCharacterAction()方法是java.nio.charset.CharsetDecoder类的内置方法,该方法针对unmappable-character错误返回此解码器的当前操作。

用法

public CodingErrorAction unmappableCharacterAction()

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


返回值:函数会针对unmappable-character错误返回此解码器的当前操作。

下面是上述函数的实现:

示例1:

// 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

示例2:

// 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–



相关用法


注:本文由纯净天空筛选整理自ShubhamMaurya3大神的英文原创作品 CharsetDecoder unmappableCharacterAction() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。