Java CharBuffer decode by UTF-8 Charset

Description

Java CharBuffer decode by UTF-8 Charset

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;

public class Main {
  public static void main(String[] args) {
    CharBuffer cb = CharBuffer.wrap("Hello");
    System.out.println(cb);/*  w w  w  .j  a  v  a 2 s . c om*/

    Charset cs = Charset.forName("UTF-8");

    ByteBuffer encodedData = cs.encode(cb);

    CharBuffer decodedData = cs.decode(encodedData);

    System.out.println(decodedData);
  }
}



PreviousNext

Related