Here you can find the source of utf8(String string)
public static byte[] utf8(String string)
//package com.java2s; //License from project: LGPL public class Main { public static byte[] utf8(String string) { try {/* w w w . jav a2 s . c o m*/ return string.getBytes("UTF-8"); } catch (Exception e) { e.printStackTrace(); return null; } } public static String utf8(byte[] bytes) { try { return new String(bytes, "UTF-8"); } catch (Exception e) { e.printStackTrace(); return null; } } }