請問:這個輸出好多0,然后加入判斷前面加0的代碼后有三位數(shù)(0ab 0bf)之類的,哪里出問題了
public?static?void?printHexByByte(String?fileName)?throws?IOException{
FileInputStream?in?=?new?FileInputStream(fileName);
byte[]?buf?=?new?byte[8?*1024];
int?bytes?=?0;
int?j?=1;
while((bytes?=?in.read(buf,0,buf.length))!=-1){
for(int?i?=?0;?i?<?bytes;?i?++){
System.out.print(Integer.toHexString(buf[i]?&?0xff)+"?");
if(j++?%?10?==?0){
System.out.println();
}
}
}
in.close();
}然后就輸出:
.....(此處省略好多行)
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 54 41 47 d4 c2?
d1 c0 cd e5 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 46 2e?
49 2e 52 2e b7 c9 b6 f9 c0 d6?
cd c5 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 b0 ae?
20 b8 e8 bc a7 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 0 0 0 0 0 0 0 0?
0 0 20 20 20 20 20 20 20 20?
20 20 20 20 20 20 20 20 20 20?
20 20 20 20 20 20 20 20 20 20?
20 20 c?
13448
2015-12-15
我覺得是你讀的文件前面很多是空的 換一個文件讀取試試看,自己寫一個txt格式的