现有一个文件 weather.info ,里面存放的是一些 UTF-8 的字符,
如:\u4eca\u5929\u767d\u5929\u5230\u591c\u95f4\uff1a... 
读取这个文件的操作我知道,但是读取出来后,但打印出来的信息还是 以上的 UTF-8 编码,我想以中文的形式显示出来,
如“阴天为主,阵雨转大雨。”
各位高手给点建议。。

解决方案 »

  1.   

    用 Hello.java 写了段测试代码,贴出来看看,运行后的结果都是显示 UTF-8 的字符 , 很闹心啊~~~
    public void EncodeingTest(){
    BufferedReader bufread; 
            String read, readStr = ""; 
            String[] weatherInfo = new String[6];
            int i=0;
     try { 
                File file = new File("D:\\weather.info"); 
                FileReader fileread = new FileReader(file); 
                bufread = new BufferedReader(fileread); 
                while ((read = bufread.readLine()) != null) { 
    //              System.out.println(read);
                 weatherInfo[i] = read;
    // weatherInfo[i] = new String(read.getBytes(),"unicode");
    //              weatherInfo[i] = new String(read.getBytes("UTF-8"));
    // weatherInfo[i] = new String(read.getBytes("UTF-8"),"unicode");
    //              weatherInfo[i] = new String(read.getBytes("unicode"),"UTF-8");
    System.out.println("weatherInfo["+i+"]= "+weatherInfo[i]);
                    i++;
                }
            } catch (Exception d) { 
                System.out.println(d.getMessage()); 
            } 
    }
      

  2.   

    你转一下字符,String ss = new String(str.getBytes("utf-8"),"gbk");//str为原来取得字符串
      

  3.   


    weatherInfo[i] = new String(read.getBytes("UTF-8"),"GBK");楼上的方法试了,不行~~~
      

  4.   


    public class TestClass { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    char[] codes = { '\u4eca', '\u5929', '\u767d', '\u5929', '\u5230',
    '\u591c', '\u95f4', '\uff1a' };
    for (int i = 0; i < codes.length; i++) {
    System.out.println(codes[i]);
    } }}
      

  5.   

    各位大虾!怎么将原来的文本转换成        char[] codes = { '\u4eca', '\u5929', '\u767d', '\u5929', '\u5230',
                    '\u591c', '\u95f4', '\uff1a' };
    文本可能是比较长的 !
      

  6.   

    你可以先把UTF - 8 转成UNICODE的,,然后转GBK ,以前我是这样转的,一般GBK 转UTF 8也是这样的,因为UNICODE可以向任何编码映射,代码现在没唉,不知道放哪了
      

  7.   

    please use your head
    public class TestClass { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String s = "\u4eca\u5929\u767d\u5929\u5230\u591c\u95f4\uff1a";
    char[] c = s.toCharArray();
    for (int i = 0; i < c.length; i++) {
    System.out.println(c[i]);
    }
    }}
      

  8.   

    感谢11楼!我编码知识太匮乏了!没有反映过来“\u4eca”就是一个字符  还要拆开看! 明白了 tks!
      

  9.   


    String s = "\\u4e2d\\u56fd"; StringBuffer sb = new StringBuffer();
    Pattern p = Pattern.compile("(?i)\\\\u([\\da-f]{4})");
    Matcher m = p.matcher(s);
    while(m.find()) {
    m.appendReplacement(sb, Character.toString((char)Integer.parseInt(m.group(1), 16)));
    }
    m.appendTail(sb); s = sb.toString();
    System.out.println(s);
      

  10.   

    import java.io.UnsupportedEncodingException;public class TestTransaction {
    public static void main(String[] args) {

    String str ="23";
    transaction(str); }

    public static String transaction(String str) {

    String s = "";
    try {
    s = new String(str.getBytes("UTF-8"),"GBK");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    return s;
    }}