url Encode with URLEncoder - Java Network

Java examples for Network:URL

Description

url Encode with URLEncoder

Demo Code


//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    public static void main(String[] argv) throws Exception {
        String input = "java2s.com";
        String charset = "java2s.com";
        System.out.println(urlEncode(input, charset));
    }/*from  w ww .  ja  va2 s .c  o  m*/

    public static String urlEncode(String input, String charset) {
        try {
            return URLEncoder.encode(input, charset);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials