Java String to Chinese GB2312 toGB2312(String s)

Here you can find the source of toGB2312(String s)

Description

Encode the string to GB2312

License

Open Source License

Parameter

Parameter Description
s The Target string

Return

The string after encode.

Declaration

public static String toGB2312(String s) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  w  w  .ja va2  s. c  o m*/
     * Encode the string to GB2312
     * 
     * @param s
     *            The Target string
     * @return The string after encode.
     */
    public static String toGB2312(String s) throws Exception {
        if (s != null && s.length() > 0) {
            byte[] byteTmp = s.getBytes("ISO8859_1");
            s = new String(byteTmp, "GB2312");
        }
        return s;
    }
}

Related

  1. isGB2312(char c)
  2. toGB2312(String s)
  3. toGb2312(String str)