为什么不能补零,上个例子为什么就可以
while((bytes = in.read(buf,0,buf.length))!=-1){
if(bytes <= 0xf){
System.out.print("0");
}
for(int i = 0 ; i < bytes;i++){
System.out.print(Integer.toHexString(buf[i] & 0xff)+" ");
if(j++%10==0){
System.out.println();
}
}
}
while((bytes = in.read(buf,0,buf.length))!=-1){
if(bytes <= 0xf){
System.out.print("0");
}
for(int i = 0 ; i < bytes;i++){
System.out.print(Integer.toHexString(buf[i] & 0xff)+" ");
if(j++%10==0){
System.out.println();
}
}
}
2015-05-17
public static void printHexByByteArrayMethod2(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++){
if((buf[i]&0xff)<=0xf){
System.out.print("0");
}
System.out.print(Integer.toHexString(buf[i] & 0xff)+" ");
if(j++%10==0){
System.out.println();
}
}
}
}
举报