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
我觉得是你读的文件前面很多是空的 换一个文件读取试试看,自己写一个txt格式的