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
  • 277,661
  • 50
  • 283
  • 320
M20
  • 872
  • 2
  • 13
  • 30

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,515
  • 2
  • 12
  • 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
  • 277,661
  • 50
  • 283
  • 320