0

I am looking for a Java instruction to convert

http://dbpedia.org/resource/NVA_%28film%29

to

http://dbpedia.org/resource/NVA_(film)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
M20
  • 1,032
  • 2
  • 15
  • 34

2 Answers2

3

Try this

URLEncoder.encode("http://www.your-url.com, "UTF-8");

and this to reverse

URLDecoder.decode(encodedString, "UTF-8");
Simon Schüpbach
  • 2,625
  • 2
  • 13
  • 26
1

I'm not aware, offhand, of easy way to do this with just the JDK classes, but Apache Commons Codec has a useful URLCodec utility:

String url = "http://dbpedia.org/resource/NVA_%28film%29";
URLCodec codec = new URLCodec();
String decodedURL = codec.decode(url);
Mureinik
  • 297,002
  • 52
  • 306
  • 350