How do you view urls in Java?

When I read xml via the InputStream URL 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 ".

As you can see, there are many "% 20".

I want url to be unescaped.

Is there a way to do this in Java without using a third-party library?

+32
java url-encoding
Mar 08 '09 at 16:46
source share
3 answers

This is not unescaped XML, it is URL encoded text. It looks like you want to use the following URL strings.

URLDecoder.decode(url); 

This will give you the correct text. The decoding result that you provided is this.

 http://cliveg.bu.edu/people/sganguly/player/ Rang De Basanti - Tu Bin Bataye.mp3 

. % 20 is a escaped space character. To get above, I used the URLDecoder object.

+54
Mar 08 '09 at 17:52
source share

I am having problems using this method when I have special characters like Γ‘ , Γ© , Γ­ , etc. My (possibly wild) assumption is that widescreen encodings are not properly encoded ... well, at least I expected to see sequences like %uC2BF , not %C2%BF .

Edited: My bad, this post explains the difference between URL encoding and JavaScript escape sequences: URI encoding in UNICODE for apache httpclient 4

+1
Feb 09 '11 at 16:45
source share

URLDecoder.decode(String s) deprecated since Java 5

You should use URLDecoder.decode(String s, String enc) .

Regarding the encoding used:

Note. The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing this can lead to incompatibilities.

0
Nov 27 '17 at 2:43 on
source share



All Articles