Here you can find the source of toUTF8(String sourceStr)
public static String toUTF8(String sourceStr) throws UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; public class Main { public static String toUTF8(String sourceStr) throws UnsupportedEncodingException { return changeEncoding(sourceStr, "ISO8859-1", "UTF-8"); }/*from ww w .j ava2 s . c o m*/ public static String changeEncoding(String sourceStr, String sourceEncoding, String targetEncoding) throws UnsupportedEncodingException { if (isEmpty(sourceStr)) { return sourceStr; } byte[] bytes = sourceStr.getBytes(sourceEncoding); return new String(bytes, targetEncoding); } public static boolean isEmpty(String sourceStr) { return (sourceStr == null || sourceStr.length() == 0); } public static String isEmpty(String sourceStr, String errorMsg) { if (isEmpty(sourceStr)) { return errorMsg; } return ""; } }