Here you can find the source of utf8Encode(String str)
public static String utf8Encode(String str)
//package com.java2s; /**/*from w w w. j a va 2s .c om*/ * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static String utf8Encode(String str) { if (!isEmpty(str) && str.getBytes().length != str.length()) { try { return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } return str; } public static String utf8Encode(String str, String defultReturn) { if (!isEmpty(str) && str.getBytes().length != str.length()) { try { return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { return defultReturn; } } return str; } public static boolean isEmpty(String str) { return (str == null || str.length() == 0); } }