需求如下:你做两个JTextArea,其中一个显示unicode的字串,另一个显示相应的中文。有谁可以提供代码或解决方案

解决方案 »

  1.   

    protected static final String ISO2GB(String ISO_8859_1String) throws java.io.UnsupportedEncodingException
      {
        String GB2312String=null;    GB2312String=new String(ISO_8859_1String.getBytes("ISO-8859-1"),"GB2312");    return GB2312String;
      }
      

  2.   

    自己写一个吧:
        InputStreamReader isr = new InputStreamReader( System.in );
        BufferedReader br = new BufferedReader( isr );
        String s = br.readLine();
        StringTokenizer st = new StringTokenizer( s, "\\u", false );
        StringBuffer sb = new StringBuffer( st.countTokens() );
        while( st.hasMoreTokens() )
          sb.append( (char)Integer.parseInt(st.nextToken(), 16) );
        System.out.println( sb.toString() );
      

  3.   

    String unicodeString =
            "\u4E0D\u8981\u8FB9\u6846\uFF0C\u53EA\u52A0\u4E0B\u5212\u7EBF";
        nativeString = unicodeString.getBytes();
        try {
            String str = new String(nativeString, 0, nativeString.length, "GB2312");
            System.out.println(str);
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }