encoding GB2312 - Java Internationalization

Java examples for Internationalization:Chinese

Description

encoding GB2312

Demo Code


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

public class Main {
    public static String encodingGB2312(String str) {
        if (str == null || str.length() == 0) {
            return null;
        }/* w w  w .j  a  va2s  . c  o m*/
        try {
            String keywords = URLEncoder.encode(str, "utf-8");
            keywords = keywords.replace("+", "%20");
            return keywords;
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;

    }
}

Related Tutorials