public static void main(String[] args) throws IOException {
//如果文件不存在,则直接创建,存在则删除后创建
FileOutputStream out = new FileOutputStream("F:\\java\\wds.txt");
//这样写,则直接在文件后面添加输出的内容
//FileOutputStream out = new FileOutputStream("F:\\java\\wds.txt",true);
//向文件中写入'A'的低字节(后八位)
out.write('A');
//写入字符串,应将字符串转换成字符数组
String s = "十几个ID死了";
byte[] b = s.getBytes();
System.out.println(b.length);
for (byte c : b)
{
out.write(c);
}
out.write(b);
//写入整数
int a = 10;
for(int i =3;i>=0;i--)
{
out.write(a>>>i*8);
}
out.close();
IOUtils.printHex("F:\\java\\wds.txt");
}12
65 202 174 188 184 184 246 73 68 203
192 193 203 202 174 188 184 184 246 73
68 203 192 193 203 00 00 00 010
我也是遇到了这个问题,我知道问题所在,但是现在还没有找到解决的方法,这个问题和前面有一节的是一样的,写入数字会有错误,会乱码,通过我的检测,这个数字写入文件会变成ASCII存储,你可以把数据改一下,对照ASCII码表,就会发现输入的数字是一一对应的。然而我还没有解决的办法。。。。
16进制10应该是00 00 00 0a