网上说用html转义字符代替,故改成这样,还是行不通。
这是部分代码,完整的代码测试过,在没有空格的地址是可以下载的。
第一次发帖求助,哪弄错了还请指教
- Java code
class DownloadService implements Runnable{ public void run() { try { String temp=http://192.168.1.100:8080/mp3/What if she is an angel.mp3; String adress=mp3Address.replace(" ", " ");System.out.println(adress); InputStream is = downloader.getInputStreamFromUrl(adress); } } public InputStream getInputStreamFromUrl(String urlStr) throws MalformedURLException, IOException { URL url = new URL(urlStr); HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); InputStream inputStream = urlConn.getInputStream(); return inputStream; }
------解决方案--------------------------------------------------------
直接对网址 进行URL编码 temp=java.net.URLEncoder.encode(temp,"utf-8");
InputStream is = downloader.getInputStreamFromUrl(temp);
------解决方案--------------------------------------------------------
%20
------解决方案--------------------------------------------------------
String adress=mp3Address.replace(" ", "+");
不过最好使用1楼所说的方法