/**
* @Comments:default:ISO-8859-1 -> UTF-8 乱码则转码
* @param: str(乱码字符),coding(default:ISO-8859-1),coding1(default:UTF-8)
* @return: str
*/
public static String toUTF8(String str,String coding,String coding1){
if(str == null) return null; //为空直接返回
String retStr = str;
try{
byte b[] = str.getBytes(null != coding && "".equals(coding)?coding:"ISO-8859-1");
for(int i = 0; i < b.length; i++){
byte b1 = b[i];
if(b1 == 63){//如果b[i]有63,不用转码;
break;
}else if(b1 > 0){//如果b[i]全大于0,那么为英文字符串,不用转码;
continue;
}else if(b1 < 0){//如果b[i]有小于0的,那么已经乱码,要转码.
retStr = new String(b,null != coding1 && "".equals(coding1)?coding1:"UTF-8");
break;
}
}
}catch(Exception e){
toThExCla(e, "Constant");
}
return retStr;
}