当前位置: 技术问答>java相关
怎么在文件末尾追加内容?
来源: 互联网 发布时间:2015-09-20
本文导语: 怎么在文件末尾追加内容? | FileOutputStream public FileOutputStream(File file) throws FileNotFoundException Creates a file output stream to write to the file represented by the specified F...
怎么在文件末尾追加内容?
|
FileOutputStream
public FileOutputStream(File file)
throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object. A
new FileDescriptor object is created to represent this file connection.
First, if there is a security manager, its checkWrite method is called with the path
represented by the file argument as its argument.
If the file exists but is a directory rather than a regular file, does not exist but cannot
be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
file - the file to be opened for writing.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file,
does not exist but cannot be created, or cannot be opened for any other reason
SecurityException - if a security manager exists and its checkWrite method denies write
access to the file.
See Also:
File.getPath(), SecurityException, SecurityManager.checkWrite(java.lang.String)
FileOutputStream
public FileOutputStream(File file,
boolean append)
throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object.
If the second argument is true, then bytes will be written to the end of the file rather than
the beginning. A new FileDescriptor object is created to represent this file connection.
First, if there is a security manager, its checkWrite method is called with the path
represented by the file argument as its argument.
If the file exists but is a directory rather than a regular file, does not exist but cannot
be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
file - the file to be opened for writing.
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file,
does not exist but cannot be created, or cannot be opened for any other reason
SecurityException - if a security manager exists and its checkWrite method denies write
access to the file.
Since:
1.4
See Also:
File.getPath(), SecurityException, SecurityManager.checkWrite(java.lang.String)
FileOutputStream
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
Creates an output file stream to write to the file with the specified name. If the second
argument is true, then bytes will be written to the end of the file rather than the
beginning. A new FileDescriptor object is created to represent this file connection.
First, if there is a security manager, its checkWrite method is called with name as its
argument.
If the file exists but is a directory rather than a regular file, does not exist but cannot
be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
name - the system-dependent file name
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file,
does not exist but cannot be created, or cannot be opened for any other reason.
SecurityException - if a security manager exists and its checkWrite method denies write
access to the file.
Since:
JDK1.1
See Also:
SecurityManager.checkWrite(java.lang.String)