Java CharBuffer encode 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 av a 2 s . c om*/ Charset cs = Charset.forName("UTF-8"); ByteBuffer encodedData = cs.encode(cb); System.out.println(encodedData); } }