`

android解决中文乱码的所有方案

 
阅读更多
解决方法:
1.修改Tomcat服务器conf\server.xml 这个文件。打开找到8080,在最后加上 URIEncoding="utf-8"
<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" 
               URIEncoding="utf-8"/>
2.程序中修改“中文”的编码。关键代码URLEncoder.encode("string","utf-8");(只要把中文部分转编码就可以了)mp3info.getMp3Name()取得MP3的名字。

utfname=URLEncoder.encode(mp3info.getMp3Name(),"utf-8");
mp3url="http://192.168.1.104:8080/mp3/"+utfname;
URL url=new URL(mp3url);
....代码略
这样就可以下载到中文名称的MP3文件了。简单吧!~.~
=================================================================================
2.XML读取得中文的问题
解决方法:在InputStreamReader中设置编码为gb2312
关键代码如下:
HttpURLConnection urlconn=(HttpURLConnection)url.openConnection();
BufferedReader   br=new BufferedReader(new InputStreamReader(urlconn.getInputStream(),"gb2312"));

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics