龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

java unicode转码为中文实例

时间:2014-06-05 15:11来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了java unicode转码为中文的实例,大家参考使用吧

代码如下:

package com.infomorrow.parser_report;

import org.junit.Test;

public class Decode {
    @Test
    public void test(){
        String uString = "\\u9053\\u8def";
        System.out.println(ascii2native(uString));//道路
    }

    public static String ascii2native(String ascii) { 
        int n = ascii.length() / 6; 
        StringBuilder sb = new StringBuilder(n); 
        for (int i = 0, j = 2; i < n; i++, j += 6) { 
            String code = ascii.substring(j, j + 4); 
            char ch = (char) Integer.parseInt(code, 16); 
            sb.append(ch); 
        } 
        return sb.toString(); 
    } 
}

精彩图集

赞助商链接