字符串的编码方式是utf-8?
1.第一种方式【java.net.URLDecoder】
String condition = URLDecoder.decode(condition, "utf-8");
2.第二种方式
String filePath = new String(filePath.getBytes("UTF-8"),"iso-8859-1");
3.第三种方式【java.net.URLEncoder】
String fileName = URLEncoder.encode(fileName, "utf-8");
在合适的地方运用合适的编码转码,就能得到良好的效果!
判断字符串的编码方式:
String iso8859 = new String(fileName.toString().getBytes("iso8859-1"));
String gbk = new String(fileName.toString().getBytes("gbk"));
String utf8 = new String(fileName.toString().getBytes("utf-8"));
if(iso8859.equals(fileName.toString())){
System.out.println("iso8859");
}else if(gbk.equals(fileName.toString())){
System.out.println("gbk");
}else if(utf8.equals(fileName.toString())){
System.out.println("utf8");
}