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,337
  • 14
  • 47
  • 83

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
  • 117,925
  • 15
  • 163
  • 179