FileOutputStream f = new FileOutputStream(fileName, true)
这里构造函数有两个参数,第二个参数表示以追加,即append的方式打开文件。
但如果不能用该构造函数,而只能使用FileOutputStream f = new FileOutputStream(fileName)的话
怎么创建以追加方式打开的FileOutputStream对象?
------解决方案--------------------
不能用该构造函数?
那你把
public FileOutputStream(File file, boolean append)
throws FileNotFoundException
{
String name = (file != null ? file.getPath() : null);
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(name);
}
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
this.append = append;
if (append) {
openAppend(name);
} else {
open(name);
}
}
改造改造,自己再写个方法好了。
直接写在FileOutputStream f = new FileOutputStream(fileName)后面,起到
FileOutputStream f = new FileOutputStream(fileName, true)
同样的效果不就ok了
真不明白,lz为什么不能用现成的构造函数。
奇怪!!!!!!!!!!!
!!!!
!!!!!
------解决方案--------------------
@since JDK1.1
public FileOutputStream(String name, boolean append)
throws FileNotFoundException
從1.1就已經存在這個constructor了,樓主誤導....