File file=new File("imooc\\a.txt");
FileInputStream in=new FileInputStream(file);
byte[] byteArray=new byte[(int)file.length];
in.read(byteArray);
for(byte b:byteArray){
if(b>=0&&b<=0xf){
System.out.print("0");
}
System.out.print(Integer.toHexString(b&0xff)+" ");
}问一下 为什么不直接获取文件的长度来 创建byte数组?
如果所处理的文件是个特别大的文件,那么这个字节数组就会太大了,多浪费内存!!整不好还能死机!!!