import java.io.UnsupportedEncodingException;
public class Encode_Decode {
public static void main(String[] args) {
String url = "This is a test_[]< > ()!#^$@%~&*";
try {
String urlencode = java.net.URLEncoder.encode(url, "UTF-8");
System.out.println("Encoding: "+urlencode);
String urldecode = java.net.URLDecoder.decode(urlencode, "UTF-8");
System.out.println("Decoding: "+urldecode);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Coding: This+is+a+test_%5B%5D%3C%3E%28%29%21%23%5E%24%40%25%7E%26*In this program, the String urlencode variable is passed as an argument in the URLEncoder.encoder.encoder method and then the result is displayed. Then, it decodes the variable encoded with URLDecoder.decode and displays the decoded url.
Decode: This is a test_[]< > ()!#^$@%~&*
Please disable your ad blocker and refresh the window to use this website.