wshyzx
2016-08-05 23:59
此处我的输出结果:
41 00 00 d6 b9
为什么会这样?
附代码:
public static void printHex(String fileName) throws IOException{
//把文件作为字节流进行读操作
FileInputStream in=new FileInputStream(fileName);
int b;
int i=1;
while((b=in.read())!=-1){
if(in.read() <= 0xf)
System.out.print("0");
System.out.print(Integer.toHexString(b)+" ");
if(i++%10==0)
System.out.println();
}
in.close();
}public class FileOutDemo1 {
public static void main(String[] args) throws IOException{
//如果该文件不存在,则直接创建;如果存在,删除后创建
FileOutputStream out=new FileOutputStream("demo/out.dat");
out.write('A');//写出了'A'的低八位
out.write('B');//写出了'B'的低八位
int a=10;//write只能写八位,那么写一个int需要写4次每次8位
out.write(a >>> 24);
out.write(a >>> 16);
out.write(a >>> 8);
out.write(a);
byte[] gbk="中国".getBytes("gbk");
out.write(gbk);
out.close();
IOUtil.printHex("demo/out.dat");
}
}
还在吗?
第七行的if语句代码 写错啦 你又读了一次
应该这样写
if(b <= 0xf)
System.out.print("0");文件传输基础——Java IO流
133848 学习 · 1060 问题
相似问题