Java CharsetDecoder malformedInputAction()方法及示例
malformedInputAction() 方法是 java.nio.charset.CharsetDecoder类 的一个内置方法,用于返回该解码器当前对畸形输入错误的操作。
语法:
public CodingErrorAction malformedInputAction()
参数 :该函数不接受任何参数。
返回值 :该函数返回该解码器当前对畸形输入错误的操作。
下面是上述函数的实现。
程序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 "
+ "malformed-input errors: "
+ decoder.malformedInputAction());
}
}
输出:
CharsetDecoder: sun.nio.cs.ext.ISO2022_CN$Decoder@232204a1
Current action for malformed-input 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 "
+ "malformed-input errors: "
+ decoder.malformedInputAction());
}
}
输出:
CharsetDecoder: sun.nio.cs.ext.DoubleByte$Decoder@232204a1
Current action for malformed-input errors: REPORT
参考资料: https://docs.oracle.com/javase/9/docs/api/java/nio/charset/CharsetDecoder.html#malformedInputAction-