`
yuanlanjun
  • 浏览: 1181225 次
文章分类
社区版块
存档分类
最新评论

Mp3乱码、中文MP3名字下载、xml中文问题解决方法

 
阅读更多

MP3乱码解决问题

InputStreamReader inputReader=new InputStreamReader(inputStream);改为
InputStreamReader inputReader=new InputStreamReader(inputStream,"GB2312");
好像有InputStreamReader的地方都要用"GB2312",用"UTF-8"不行.

1.中文MP3名字下载问题
http://192.168.1.104:8080/mp3/a1.mp3这样可以下载到
http://192.168.1.104:8080/mp3/勇气.mp3 出现中文名字就下载不到了。

解决方法:
1.修改Tomcat服务器conf\server.xml 这个文件。打开找到8080(我的Tomcat有两段port="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