怎样用JAVA实现GB-2312到Big-5或Unicode的编码转换,哪位兄弟姐妹做过这方面的程序,给点建议吧!
小弟刚刚接触,不知从何下手.
谢谢啊

解决方案 »

  1.   


    /**
     * GB to Unicode
     * @param strIn
     * @return String
     */
    public static String GBtoISO(String strIn) {
    byte[] b;
    String strOut = null;
    if (strIn == null || (strIn.trim()).equals("")) { return strIn; }
    try {
    b = strIn.getBytes("GBK");
    strOut = new String(b, "ISO8859_1");
    } catch (UnsupportedEncodingException e) {
    }
    return strOut;
    }
    /**
     * 
     * @param s
     * @return
     */
    public final static byte[] getBytes(String s) {
    if (s != null) {
    try {
    return s.getBytes("Unicode");
    } catch (Exception ex) {
    //ignore, can't ocure
    }
    }
    return null;
    }
    /**
     * 
     * @param s
     * @return
     */
    public final static String toString(byte[] s) {
    if (s != null) {
    try {
    return (new String(s, "Unicode"));
    } catch (Exception ex) {
    //ignore, can't ocure
    }
    }
    return null;
    } /**
     * unicodeToGB
     * @param strIn
     * @return String
     */
    public static String ISOToGB(String strIn) {
    byte[] b;
    String strOut = null;
    if (strIn == null || (strIn.trim()).equals("")) { return strIn; }
    try {
    b = strIn.getBytes("ISO8859_1");
    strOut = new String(b, "GBK");
    } catch (UnsupportedEncodingException e) {
    }
    return strOut;
    }
      

  2.   

    我先创建一个字符传,然后调用ISOToGB方法,最后将原来的字符传和返回的字符传打印,
    结果被转换成GB的字符传打印结果是:??这是怎么回事啊,百思不得其解?
    对了我用 
    str = new String ("天上人间");
    创建的字符传.
      

  3.   

    我加了一个主方法,如下:
    public static void main(String Args[])
    {
     //CodeTransformer CT = new CodeTransformer();
     String strISO = new String("天上人间");
     System.out.println(strISO);
     System.out.println(CodeTransformer.ISOToGB(strISO)); 
    }输出:
    天上人间
    ????那几个问号是什么意思?
    我怎样才能验证编码确实被转换了??
    谢谢!
      

  4.   

    另外:
    ISO-8859-1:ISO拉丁字母表 No.1,也叫作 ISO-LATIN-1 
    它并不是unicode字符集。