java.nio.charset.CodingErrorAction Class in Java Last Updated : 21 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In Java programming, Character encoding plays an important when we talk about handling data and information across different systems. The java.nio.charset package contains classes for managing character encoding and decoding. CodingErrorAction class is one of the package's core classes. This class describes the actions to be taken when an encoding or decoding issue arises. The java.nio.charset.CodingErrorAction class is an enum representing different actions to be handled in response to encoding or decoding errors. These actions help the developer to define how the encoding or decoding process will proceed once unexpected situations occur. Methods of java.nio.charset.CodingErrorAction ClassMethod Description toString() Returns a string describing this action. Fields of java.nio.charset.CodingErrorAction ClassField Description IGNORE Error should be handled by dropping the erroneous input and resuming the coding operation REPLACE Error should be handled by dropping the erroneous input, appending the replacement value to the output buffer REPORT Error is to be reported to the developer ExampleLet's take an example where we will be using java.nio.charset.CodingErrorAction IGNORE property to ignore the exceptions caused during encoding or decoding. Java import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.nio.charset.CodingErrorAction; public class CodingErrorActionShortExample { public static void main(String[] args) { Charset charset = Charset.forName("ISO-8859-1"); CharsetEncoder encoder = charset.newEncoder(); // Set the coding error action to IGNORE encoder.onMalformedInput(CodingErrorAction.IGNORE) .onUnmappableCharacter(CodingErrorAction.IGNORE); String input = "Hello, 你好, नमस्ते"; CharBuffer charBuffer = CharBuffer.wrap(input); ByteBuffer byteBuffer = ByteBuffer.allocate(50); try { encoder.encode(charBuffer, byteBuffer, true); byteBuffer.flip(); while (byteBuffer.hasRemaining()) { System.out.print((char) byteBuffer.get()); } } catch (Exception e) { e.printStackTrace(); } } } Output: Hello, , Comment More infoAdvertise with us Next Article java.nio.charset.CodingErrorAction Class in Java K kirandeepkaurguler Follow Improve Article Tags : Java Java-Classes Practice Tags : Java Similar Reads java.nio.charset.CoderResult Class in Java The 'java.nio.charset' package in Java contains classes for character encoding and decoding. The CoderResult class is used for determining the outcome of an encoding or decoding operation. Before we get started, let's review the ideas behind character encoding and decoding in CoderResult. The proces 6 min read java.nio.charset.CharsetEncoder Class in Java For the purpose of character encoding and decoding, java offers a number of classes in the 'java.nio.charset' package. The 'CharsetEncoder' class of this package performs the important task of encoding. In this article, let us understand this class, its syntax, different methods, and some examples o 6 min read java.nio.charset.Charset Class in Java In Java, Charset is a mapping technique used in Java to map the 16-bit Unicode sequence and sequences of bytes. It is also used to encode and decode the string data text into different character encoding. It comes under java.nio.charset.Charset package. The charset must begin with a number or letter 2 min read Java.lang.Character.UnicodeBlock Class in Java Character.UnicodeBlock Class represents particular Character blocks of the Unicode(standards using hexadecimal values to express characters - 16 bit) specifications. Character Blocks define characters used for specific purpose. Declaration : public static final class Character.UnicodeBlock extends C 2 min read Chars Class | Guava | Java Chars is a utility class for primitive type char. It provides Static utility methods pertaining to char primitives, that are not already found in either Character or Arrays. All the operations in this class treat char values strictly numerically, i.e, they are neither Unicode-aware nor locale-depend 3 min read Like