你如何在Java中浏览URL? [英] How do you unescape URLs in Java?
问题描述
当我通过URL的InputStream读取xml,然后删除除url之外的所有内容时,我得到 http://cliveg.bu.edu/people/sganguly/player/%20Rang%20De%20Basanti%20-%20Tu%20Bin% 20Bataye.mp3 。
When I read the xml through a URL's InputStream, and then cut out everything except the url, I get "http://cliveg.bu.edu/people/sganguly/player/%20Rang%20De%20Basanti%20-%20Tu%20Bin%20Bataye.mp3".
正如你所看到的,有很多%20。
As you can see, there are a lot of "%20"s.
我想要的网址未转义。
有没有办法在Java中这样做而不使用第三方库?
Is there any way to do this in Java, without using a third-party library?
推荐答案
这不是未转义的XML,这是URL编码的文本。在我看来,你想在URL字符串上使用以下内容。
This is not unescaped XML, this is URL encoded text. Looks to me like you want to use the following on the URL strings.
URLDecoder.decode(url);
这将为您提供正确的文字。您提供的解码结果就是这样。
This will give you the correct text. The result of decoding the like you provided is this.
http://cliveg.bu.edu/people/sganguly/player/ Rang De Basanti - Tu Bin Bataye.mp3
%20是一个转义空格字符。为了得到上述内容,我使用了URLDecoder对象。
The %20 is an escaped space character. To get the above I used the URLDecoder object.
这篇关于你如何在Java中浏览URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!