在复制文件时当一次读取一个字节数组或一个字符数组时,先实例化一个数组,再声明一个读取长度:
字节流:
byte [] b = new byte[1024];
int len = 0;
while((len = in.read(b)) != -1){
out.write(b,0,len);
}
字符流:
char [] c = new char [1024];
int len = 0;
while((len = in.read(c)) != -1){
out.write(c, 0, len);
}
|
|