当前位置:课程学习>>第七章 输入输出流>>学习内容>>知识点一
同学们,请运用你学到的知识,尝试分析下面的案例。
案例:给出文件hello.txt,请说出下列语句的作用。
1.try{ OutputStream out=new FileOutputStream(“hello.txt”);
}catch(IOException e){}
2.try{ OutputStream out=new FileOutputStream(“hello.txt”,true);
}catch(IOException e){}
3.try{OutputStream out=new FileOutputStream(“hello.txt”,false);
}catch(IOException e){}
1.删除hello.txt文件已有内容,然后再写入新内容。
2.将数据添加到hello.txt文件已有内容的末尾处。
3.删除hello.txt文件已有内容,然后再写入新内容。
public FileOutputStream(String name, Boolean append) throws FileNotFoundException
这个构造方法中,前者的参数name是用来指定文件名,指定数据要写入的文件,而后者的第二个参数append用来表明写入的方式。当参数appned为true时,数据将添加到文件已有内容的末尾处。而当参数append为false时,文件已有的内容将被删除,然后再写入新内容。