当前位置:   article > 正文

java打印unicode_用java实现打印汉字的Unicode和GBK编码一览表

java 打印 unicode 十进制 emoji

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.io.UnsupportedEncodingException;

public class ChineseCharEncodingList{

private static final int MIN_INDEX = 19968;

private static final int MAX_INDEX = 40869;

private static final String CR = "\r\n";

private static final String TAB = "\t";

public void execute(String fileName) throws IOException{

File f = new File(fileName);

FileWriter fw = new FileWriter(f);

fw.write("字符"+TAB+"Unicode十进制"+TAB+"Unicode十六进制"+TAB+TAB+"GBK十进制"+TAB+"GBK十六进制"+CR);

fw.write("=================================================================================="+CR);

int GBKCode;

for(int i=MIN_INDEX;i<=MAX_INDEX;i++){

GBKCode = getGBKCode(i);

fw.write((char)i+TAB+i+TAB+TAB+Integer.toHexString(i)+TAB+TAB+TAB+GBKCode+TAB+TAB+Integer.toHexString(GBKCode)+CR);

}

fw.flush();

System.out.println("Done!");

}

private int getGBKCode(int unicodeCode) throws UnsupportedEncodingException{

char c = (char) unicodeCode;

byte[] bytes = (c+"").getBytes("GBK");

return ((bytes[0]&255)<<8) + (bytes[1]&255);

}

public static void main(String[] args) throws Exception{

new ChineseCharEncodingList().execute("汉字编码一览表.txt");

}

}

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2009-05-05 17:52

浏览 2694

评论

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/179599
推荐阅读
相关标签
  

闽ICP备14008679号