Java CharsetEncoder .encode (CharBuffer in)

Syntax

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

public final ByteBuffer encode(CharBuffer in)   throws CharacterCodingException

Example

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


//  w w  w .  j  av  a  2s.  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 = "java2s.com";
    System.out.println(encoder.encode(CharBuffer.wrap(response)));
  }
}




















Home »
  Java Tutorial »
    java.nio.charset »




Charset
CharsetDecoder
CharsetEncoder
StandardCharsets