2010-09-20 69 views
4

我是从URL中使用XML解析显示图像,一些图像显示得非常好,有一段时间我有例外,像如何解决这个异常路径中的非法字符?

Illegal character in path at index 113: http://www.theblacksheeponline.com/party_img/thumbspps/12390867930_15951_186997180114_709920114_4296270_6115611_n[1].jpg 

我怎样才能解决这个问题,有人知道,请给一些示例代码我。 ..

感谢所有

+0

可能重复的[如何处理URISyntaxException](http://stackoverflow.com/questions/749709/how-to-deal-with-the-urisyntaxexception) – 2016-07-06 15:06:22

回答

9

特别characte RS需要转义[并%5D]如%5B

您可以使用java.net.URLEncoder到URL编码为

java.net.URLEncoder

URLEncoder.encode(myurltoencode,"UTF-8");

这将不只是修复[或],还包括其他编码问题

4

使用了[%5B 和闭幕]这种逃避的代码中使用%5D

0

这奏效了:

URL url = new URL("http://www.theblacksheeponline.com/party_img/thumbspps/12390867930_15951_186997180114_709920114_4296270_6115611_n[1].jpg"); 
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); 

URLEncoder的用于Web表单application/x-www-form-urlencoded MIME类型 - 而不是http网络地址。

相关问题