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数组是我要合并多少个文件就要写多个吗?
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数组是我要合并多少个文件就要写多个吗?
但是不是read(b)先执行吗?创建了b数组,里面什么都没有,那么read读出来的是什么?
同理.write()对数组的操作也是
u012350685
u012677436
u012208408
u010863631
这些都是神马人...