日期:2014-05-20  浏览次数:20669 次

求教关于IO里面byte数组的作用
public class CopyFiles {

public static void main(String[] args) throws IOException{
FileInputStream fis = new FileInputStream("D:"+File.separator+"test"+File.separator+"m01.gif");
FileOutputStream fos = new FileOutputStream("D:"+File.separator+"test"+File.separator+"m02.gif");
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] b = new byte[1024*2];
int length = 0;
while((length = bis.read(b)) != -1){
bos.write(b, 0, length);
bos.flush();
}
bis.close();
bos.close();
}
}


今天老师讲了IO,很多例子里面都有这个自定义的byte数组,读和写的时候都要用到这个数组,请问这个数组有什么用。都说是把文件里面的东西读到这个数组里面,但是没见到有任何操作这个数组的代码呀?仅仅是创建了啊~~~

还有,我在写合并多个txt文件的程序时,这个byte数组是我要合并多少个文件就要写多个吗?

------解决方案--------------------
bos.write(b, 0, length); 这句就是啊
------解决方案--------------------
read(b)是从bis里读数据,里面当然是有东西的,然后write(b)把数组里的东西写到bos中
------解决方案--------------------
read(byte[] b) 是将读到的内容放进这个数组中..至于怎么放..这个是底层实现的..我们不用理
同理.write()对数组的操作也是