URLEncoding & URLDecoding in Java

1 view
Skip to first unread message

Arjun Sridhar UR

unread,
Mar 20, 2015, 4:37:41 AM3/20/15
to arjunsr...@googlegroups.com
URL DeCoding

package com.yaazli.corejava.networking;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class URLDecoding {
public static void main(String a[]){

       try {
   System.out.println(URLDecoder.decode("String%20without%20spaces","UTF-8"));

       }
       catch (UnsupportedEncodingException ex) {

           ex.printStackTrace();
       }
   }
}

URLEncoding

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class URLEncoding {

    public static void main(String a[]){

        try {
    System.out.println(URLEncoder.encode("String with spaces","UTF-8"));
    System.out.println(URLEncoder.encode("String with spaces encoded","UTF-8").replace("+", "%20"));

        }
        catch (UnsupportedEncodingException ex) {

            ex.printStackTrace();
        }
    }
}

Reply all
Reply to author
Forward
0 new messages