分类:
2009-04-28 09:06:18
我用java程序实现了由机器自动生成国标码。其基本思想是用循环产生每个字节的ASCII码,然后连接两个字节的字符串,再以文本形式输出到二进制文件中。代码如下:
import java.io.*;
public class GB2312_80 {
public static void main(String args[]) throws IOException{
File newDir = new File("d:\\java\\test2");
File newFile = new File(newDir, "GB2312_80.chr");
if (!newFile.exists()){
newFile.createNewFile();
}
RandomAccessFile newFileW = new RandomAccessFile(newFile, "rw");
int i, j;
for(i = 161; i < 255; i++)
for (j = 161; j < 255; j++){
String m1 = Integer.toString(i,2); //将ASCII码值(十进制)转换为二进制字符串
String n1 = Integer.toString(j, 2);
String x = m1 + n1; //连接两个字符串使之变为16位的字符串(即两个字节)
long x1 = Long.parseLong(x, 2); //将字符串转换为长整型数据
newFileW.writeLong(x1); //输出字符
}
}
}