Java IO Tutorial - Java CharsetEncoder .isLegalReplacement (byte[] repl)








Syntax

CharsetEncoder.isLegalReplacement(byte[] repl) has the following syntax.

public boolean isLegalReplacement(byte[] repl)

Example

In the following code shows how to use CharsetEncoder.isLegalReplacement(byte[] repl) method.

/*from w  w  w. j av a2  s  . c  o  m*/
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

public class Main {
  public static void main(String[] args) throws Exception{
    CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();

    System.out.println(encoder.isLegalReplacement(new byte[]{}));
  }
}

The code above generates the following result.