Android examples for java.lang:String UTF-8
Get String of utf-8
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { /**// w w w.j a v a 2 s . co m * * * @return XML-Formed string */ public static String getString2UTF8(String str) { // A StringBuffer Object StringBuffer sb = new StringBuffer(); sb.append(str); String xmString = ""; String xmlUTF8 = ""; try { xmString = new String(sb.toString().getBytes("UTF-8")); xmlUTF8 = URLEncoder.encode(xmString, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return xmlUTF8; } }