Url Encoding and Decoding in Java

URL encoding/decoding in java is very useful while working with the URL which is transmitted through the network. In case your URL contains some special characters in it then it might get replaced with some other special character.

Few important notes,

  • Always use the same scheme to encode and decode the URL.
  • URLs can be encoded multiple times hence always keep this in mind while comparing or retrieving the original URL.
  • Before encoding, recommendation is to decode the URL first and see if resulted URL differs from original URL which means URL is already encoded.

Sample Java Code

Leave a Reply

Your email address will not be published. Required fields are marked *