-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChineseCharEncoding.java
More file actions
40 lines (39 loc) · 1.34 KB
/
ChineseCharEncoding.java
File metadata and controls
40 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
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 class ChineseCharEncoding
{
public static void main(String[] args) throws Exception
{
new ChineseCharEncodingList().execute("e:\\汉字编码一览表.txt");
}
}