读书人

请问构造FileOutputStream的有关问题

发布时间: 2012-01-18 00:23:26 作者: rapoo

请教构造FileOutputStream的问题
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了,主....

读书人网 >J2SE开发

热点推荐