package java.io;
/**
* 写字符文件的方便类。
* 这个类的构造函数假定默认的字符编码和默认的字节缓存都是可以接受的。
* 要自己指定这些值,请在FileOutputStream上构造一个outputstreamwriter。
*
* <p>文件是否可用或是否可以创建取决于底层平台。
* 特别是,某些平台一次只允许一个FileWriter(或其他文件写入对象)打开一个文件进行写入。
* 在这种情况下,如果涉及的文件已经打开,该类中的构造函数将失败。
*
* <p>FileWriter是用来写字符流的。
* 对于写入原始字节流,可以考虑使用FileOutputStream。
*
* @see OutputStreamWriter
* @see FileOutputStream
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class FileWriter extends OutputStreamWriter {
/**
* 构造一个给定文件名的FileWriter对象。
*
* @param fileName String The system-dependent filename.
* @throws IOException if the named 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
*/
public FileWriter(String fileName) throws IOException {
super(new FileOutputStream(fileName));
}
/**
* 构造一个给定文件名的FileWriter对象,并使用一个布尔值指示是否追加写入的数据。
*
* @param fileName String The system-dependent filename.
* @param append boolean if <code>true</code>, then data will be written
* to the end of the file rather than the beginning.
* @throws IOException if the named 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
*/
public FileWriter(String fileName, boolean append) throws IOException {
super(new FileOutputStream(fileName, append));
}
/**
* 构造一个给定文件对象的FileWriter对象。
*
* @param file a File object to write to.
* @throws IOException 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
*/
public FileWriter(File file) throws IOException {
super(new FileOutputStream(file));
}
/**
* 构造给定File对象的FileWriter对象。
* 如果第二个参数为true,那么字节将被写入文件的末尾而不是开头。
*
* @param file a File object to write to
* @param append if <code>true</code>, then bytes will be written
* to the end of the file rather than the beginning
* @throws IOException 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
* @since 1.4
*/
public FileWriter(File file, boolean append) throws IOException {
super(new FileOutputStream(file, append));
}
/**
* 构造一个与文件描述符关联的FileWriter对象。
*
* @param fd FileDescriptor object to write to.
*/
public FileWriter(FileDescriptor fd) {
super(new FileOutputStream(fd));
}
}