中文转换成 utf-8编码
public static String toUtf8String(String s) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
//System.out.println(b.length+":"+b.toString());
} catch (Exception ex) {
System.out.println(ex);
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
//System.out.println(k);
if (k < 0)
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase
());
}
}
}
//System.out.println("final"+sb);
return sb.toString();
}