Java URLEncoder encode as UTF-8

Description

Java URLEncoder encode as UTF-8


import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    public static void main(String[] argv) throws Exception {
        String before = "";
        System.out.println(Encode(before));
    }/*from  www .  jav  a  2s. c om*/

    static String Encode(String before) {
        String after = null;
        try {
            after = URLEncoder.encode(before, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return after;
    }
}



PreviousNext

Related