How do you unescape URLs in Java?

Starting from Java 11 use

URLDecoder.decode(url, StandardCharsets.UTF_8).

for Java 7/8/9 use URLDecoder.decode(url, "UTF-8").

URLDecoder.decode(String s) has been deprecated since Java 5

Regarding the chosen encoding:

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.


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

The %20 is an escaped space character. To get the above I used the URLDecoder object.