关于write()方法的append问题
以下是摘自FileOutputStream的部分源码:
public FileOutputStream(File file) throws FileNotFoundException {
this(file, false);
}
public FileOutputStream(File file, boolean append) throws FileNotFoundException{
...
this.append = append;
...
}
可以看到创建FileOutput默认append属性为false,即不会追加到文件末尾。
但是。
复制文件的时候有部分代码如下:
while ((len = in.read(buf, 0, buf.length)) != -1) {
out.write(buf, 0, len);
}
为什么这里的write()方法不会覆盖之前写入的字节。