File fis=new File();tempByte是一个字节数组,大概意思是从文件中读取固定tempByte大小的字节,然后对尾巴处理
但是还是有些模糊,大侠能每行给个解释吗?tempByte。length返回的是什么?
while ((flag = fis.read(tempByte)) > 0) / /循环从源文件中读取数据存入到字节数组里{ if (flag < tempByte.length)
{ //对文件尾巴的处理
byte[] tempByte1 = new byte[flag];
for (int i = 0; i < flag; i++)
{
tempByte1[i] = tempByte[i];
}
tempByte = tempByte1;
}
}
但是还是有些模糊,大侠能每行给个解释吗?tempByte。length返回的是什么?
while ((flag = fis.read(tempByte)) > 0) / /循环从源文件中读取数据存入到字节数组里{ if (flag < tempByte.length)
{ //对文件尾巴的处理
byte[] tempByte1 = new byte[flag];
for (int i = 0; i < flag; i++)
{
tempByte1[i] = tempByte[i];
}
tempByte = tempByte1;
}
}
FileInputStream(File file)
----------------------------
File fis=new File();
FileInputStream fs =new FileInputStream(File fis);
fs这个对象才是处理数据的
给你个byte 的数组tempByte 比如长度200
fs.read(tempByte) 返回值最大200,实际值小于等于200,
自己处理的时候没有必要处理200,只要处理实际填充数组的那个长度,即方法的返回值长度(<=200)。