用native2ascii工具将中文字符转换成类似下面的unicode字符,保存在test.csv中:
\u5c0f\u8717,\u5c0f\u8717,\u5c0f\u8717,\u5c0f\u8717现在想读取test.csv中的unicode字符,并把它转换回中文显示到Frame上,怎么处理?java读取properties文件的方法不适合csv文件,有没有别的方法?

解决方案 »

  1.   

    String s = "\u5c0f\u8717,\u5c0f\u8717,\u5c0f\u8717,\u5c0f\u8717";
            System.out.println(s.charAt(0));//输出“小”
      

  2.   

    import java.util.*; 
    import java.io.*;
    public class MyNative{ 
    public static void main(String [] args) throws Exception{ 
            Properties properties = new Properties();
            properties.load(new FileInputStream("test.scv"));
            for(Iterator iter = properties.entrySet().iterator();iter.hasNext();){
             String s = iter.next().toString();
             System.out.println("::"+s.substring(0,s.length()-1));
            }

    }
      

  3.   

    /*
         * Converts encoded \uxxxx to unicode chars
         * and changes special saved chars to their original forms
         */
        private String loadConvert (char[] in, int off, int len, char[] convtBuf) {
            if (convtBuf.length < len) {
                int newLen = len * 2;
                if (newLen < 0) {
            newLen = Integer.MAX_VALUE;
        } 
        convtBuf = new char[newLen];
            }
            char aChar;
            char[] out = convtBuf; 
            int outLen = 0;
            int end = off + len;        while (off < end) {
                aChar = in[off++];
                if (aChar == '\\') {
                    aChar = in[off++];   
                    if(aChar == 'u') {
                        // Read the xxxx
                        int value=0;
        for (int i=0; i<4; i++) {
            aChar = in[off++];  
            switch (aChar) {
              case '0': case '1': case '2': case '3': case '4':
              case '5': case '6': case '7': case '8': case '9':
                 value = (value << 4) + aChar - '0';
         break;
      case 'a': case 'b': case 'c':
                              case 'd': case 'e': case 'f':
         value = (value << 4) + 10 + aChar - 'a';
         break;
      case 'A': case 'B': case 'C':
                              case 'D': case 'E': case 'F':
         value = (value << 4) + 10 + aChar - 'A';
         break;
      default:
                                  throw new IllegalArgumentException(
                                               "Malformed \\uxxxx encoding.");
                            }
                         }
                        out[outLen++] = (char)value;
                    } else {
                        if (aChar == 't') aChar = '\t'; 
                        else if (aChar == 'r') aChar = '\r';
                        else if (aChar == 'n') aChar = '\n';
                        else if (aChar == 'f') aChar = '\f'; 
                        out[outLen++] = aChar;
                    }
                } else {
            out[outLen++] = (char)aChar;
                }
            }
            return new String (out, 0, outLen);
        }这是 java.util.Properties 类中的源代码,将字符串 "\\uxxxx" 转换成一个字符,让人有些泄气。
      

  4.   

    我以前的一点笔记,希望能够帮上忙。
    http://blog.donews.com/frankyl/archive/2005/08/11/503609.aspx
      

  5.   

    先按","查找到各个需要decode的字符串,然后使用上述连接中代码的decodeString()函数不需要任何修改即可完成decode工作。