Java获取GB2312所有汉字

Java获取GB2312所有汉字

GB2312中汉字的编码范围为,第一字节0xB0-0xF7(对应十进制为176-247),第二个字节0xA0-0xFE(对应十进制为160-254)

import java.io.File;
import java.io.FileWriter;

/**
 * @author lingkang
 * @date 2021/10/4 16:46
 * @description
 */
public class Test01 {
    public static void main(String[] args) throws Exception {
        StringBuffer buffer = new StringBuffer();
        byte[] by = new byte[2];
        for (int b1 = 176; b1 < 248; b1++) {
            by[0] = (byte) b1;
            for (int b2 = 161; b2 < 255; b2++) {
                by[1] = (byte) b2;
                String str = "";
                buffer.append(new String(by, "GB2312"));
            }
            System.out.print(buffer.toString());
            FileWriter writer=new FileWriter(new File("C:\\Users\\Administrator\\Desktop\\gb2312.txt"));
            writer.write(buffer.toString());
            writer.flush();
            writer.close();
        }
    }
}
posted @ 2022-09-16 00:08  凌康  阅读(74)  评论(0编辑  收藏  举报