Java IO Tutorial - Java CharsetEncoder .encode (CharBuffer in)


CharsetEncoder.encode(CharBuffer in) has the following syntax.

public final ByteBuffer encode(CharBuffer in)   throws CharacterCodingException


In the following code shows how to use CharsetEncoder.encode(CharBuffer in) method.

//from www .  j av a 2 s. c o m
import java.nio.CharBuffer;
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();

    String response = "";

The code above generates the following result.