Java URLEncoder URLDecoder Example
In this tutorial, I am sharing about Simple Java URLEncoder URLDecoder Example Program. Thr program has been tested and output is shared in the same post.
URLEncodeDecode.java
package com.dineshkrish.networking; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; public class URLEncodeDecode { private static final String ENC = "UTF-8"; // URL Encoding method public static String encode(String value) { try { value = URLEncoder.encode(value, ENC); } catch (UnsupportedEncodingException e) { System.out.println(e.getMessage()); e.printStackTrace(); } return value; } // URL Decoding method public static String decode(String value) { try { value = URLDecoder.decode(value, ENC); } catch (UnsupportedEncodingException e) { System.out.println(e.getMessage()); e.printStackTrace(); } return value; } public static void main(String[] args) { String data = "C C++ Java Pyhton Ruby PHP"; System.out.println("Orginal data : "+data); String encodedData = encode(data); System.out.println("Encoded Data : "+encodedData); String decodedData = decode(encodedData); System.out.println("Decoded Data : "+decodedData); } }
Output
—————
Orginal data : C C++ Java Pyhton Ruby PHP
Encoded Data : C+C%2B%2B+Java+Pyhton+Ruby+PHP
Decoded Data : C C++ Java Pyhton Ruby PHP
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet