url Decode - Java Network

Java examples for Network:URL

Description

url Decode

Demo Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {
    public static void main(String[] argv) throws Exception {
        String value = "java2s.com";
        System.out.println(urlDecode(value));
    }/*from   w  w  w  . j  a v  a 2  s.c  om*/

    public static String urlDecode(String value, boolean escapePlus) {
        if (escapePlus) {
            return urlDecode(value.replace("+", "%2B"));
        } else {
            return urlDecode(value);
        }
    }

    public static String urlDecode(String value) {
        if (value == null)
            return value;
        try {
            return URLDecoder.decode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials