java.io.FileOutputStream的构造函数:

①FileOutputStream(File file) 

②FileOutputStream(String name) 

③FileOutputStream(File file, boolean append) 

④FileOutputStream(String name, boolean append) 

⑤FileOutputStream(FileDescriptor fdObj)

(1)构造函数①②都是通过文件路径(或其标识的File对象)来创建文件流。

注意:

若文件不存在(待查:是否会创建文件);

若文件存在,则方法①②中有打开文件的操作;

若文件给定的是目录而不是文件,或文件不存在又不能创建,再或者文件存在却不能打开,抛出异常"FileNotFoundException";

若文件由于安全保护而不允许读取,抛出异常"SecurityException"  

(2)写文件有两种方法,一种是从文件头写入(覆盖原有数据),另一种是从文件尾写入(增加数据)。

构造函数①②都是按照前者实现的,从文件头写入;

构造函数③④的入参中多了一个append参数,若参数值为true,则是“追加数据”。若参数值为false,则“覆盖原有数据”,即退化成①②函数的功能。

 

posted on 2016-04-10 21:03  小鹿BAMBI  阅读(5857)  评论(0编辑  收藏  举报