Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static String str2UTF8(String str) { return str2Code(str, "UTF-8"); } public static String str2Code(String str, String code) { try { str = new String(str.getBytes(), code); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return str; } }