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
<Connector port="8888" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
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();
}