我搜索了帖子后发现
有些人是
String tempStr = "中文";//准备转换的字符
String result = new String(tempStr.getBytes("GB2312"),"UTF-8");//转换后的结果好像这样对码?
我要的中文转UTF-8这样写对吗?
有些人是
String tempStr = "中文";//准备转换的字符
String result = new String(tempStr.getBytes("GB2312"),"UTF-8");//转换后的结果好像这样对码?
我要的中文转UTF-8这样写对吗?
String result =java.net.URLEncoder.encode(tempStr,"utf-8")
String tempStr =java.net.URLEncoder.encode(tempStr,"utf-8")
String encoding=System.getProperty("file.encoding");
encoding就是当前编码.2,如何转换成utf-8格式编码:我给你写了个函数,用来转换
中文字符编码,转换成utf-8格式的:/**
* inParam:需要转换的gb2312中文字符
* 返回:该中文字符对应的UTF-8编码的字符
*/
public static String toUTF(String inPara){
char temChr;
int ascChr;
int i;
String rtStr=new String("");
if(inPara==null){
inPara="";
}
for(i=0;i<inPara.length();i++){
temChr=inPara.charAt(i);
ascChr=temChr+0;
rtStr=rtStr+"&#x"+Integer.toHexString(ascChr)+";";
}
return rtStr;
}