Here you can find the source of utf8encode(String str)
public static byte[] utf8encode(String str)
//package com.java2s; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; public class Main { private static final CharsetEncoder UTF8_ENCODER = Charset.forName( "UTF-8").newEncoder(); public static byte[] utf8encode(String str) { try {/*from www .j ava 2 s . c om*/ return UTF8_ENCODER.encode(CharBuffer.wrap(str)).array(); } catch (CharacterCodingException ex) { throw new RuntimeException(ex); } } }