【发布时间】:2012-05-13 17:46:32
【问题描述】:
我编写了一个类,该类通过创建一些并行下载来获取文件。我使用下面的简单代码进行任何下载:
DefaultHttpClient conn = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(new URI(M_url));
HttpResponse = conn.execute(httpPost);
在某些文件链接(M_url)中,程序没问题,但是当我想下载包含 [ ] 等字符的链接时,发生了 URISyntaxException。例如链接http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zip错误如下:
java.net.URISyntaxException:索引 48 处路径中的非法字符: http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zipException 在线程“主”java.lang.NullPointerException
解决此问题的编程解决方案是什么?我使用以下代码,但这不能解决我的问题:
M_url = URLEncoder.encode(M_url, "UTF-8")
在此先感谢,如果此主题与类似主题重复,我们深表歉意。
【问题讨论】:
-
stackoverflow.com/questions/749709/… .. 也许这可以帮助你