解决 Android 上载中文文件名有关问题
解决 Android 下载中文文件名问题
1、tomcat6.x 服务器
2、android 虚拟器下载文件
如下载服务器上文件: 测试.MP3
下载路径:http://192.168.1.110:8080/mp3/测试.mp3
解决办法:
1.先在设置服务器编码:找到Tomcat安装目录下的server.xml文件(Tomcat 6.0\conf\server.xml)。设置编码为UTF-8
<Connectorport="8080" URIEncoding="UTF-8" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>
2. android 中代码为:
String UrlStr = "http://192.168.1.110:8080/mp3/"+URLEncoder.encode(测试.mp3,"UTF-8");
try {
URL url = new URL(UrlStr);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
inputStream =urlConn.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
OK
1 楼
andytang_bin
2011-07-13
还是不行。 能Q上联系吗?!
2 楼
andytang_bin
2011-07-13
我QQ 912180974