2

I've got String Ruby On Rails, it should be converted to Ruby%20On%20Rails, but URLEncoder says Ruby+On+Rails. This is my try:

String encoded = URLEncoder.encode("Ruby On Rails");
System.out.println(encoded);

Is it happening because encode() method is deprecated?

Tony
  • 3,605
  • 14
  • 52
  • 84

1 Answers1

2

URLEncoder doesn't do URI encoding, it does application/x-www-form-urlencoded, which converts spaces to + signs. If you want them converting to %20 then you need something that does URI encoding instead, such as Spring's UriUtils.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183