public class FileWriter extends OutputStreamWriter
文件是否可用或可能被创建取决于底层平台。 特别是某些平台允许一次只能打开一个文件来写入一个FileWriter (或其他文件写入对象)。 在这种情况下,如果所涉及的文件已经打开,则此类中的构造函数将失败。
FileWriter是用于写入字符流。 要编写原始字节流,请考虑使用FileOutputStream 。
OutputStreamWriter , FileOutputStream
| Constructor and Description |
|---|
FileWriter(File file)
给一个File对象构造一个FileWriter对象。
|
FileWriter(File file, boolean append)
给一个File对象构造一个FileWriter对象。
|
FileWriter(FileDescriptor fd)
构造与文件描述符关联的FileWriter对象。
|
FileWriter(String fileName)
构造一个给定文件名的FileWriter对象。
|
FileWriter(String fileName, boolean append)
构造一个FileWriter对象,给出一个带有布尔值的文件名,表示是否附加写入的数据。
|
close, flush, getEncoding, write, write, writepublic FileWriter(String fileName) throws IOException
fileName - String系统相关的文件名。
IOException - 如果命名文件存在但是是一个目录而不是常规文件,则不存在但不能创建,或由于任何其他原因无法打开
public FileWriter(String fileName, boolean append) throws IOException
fileName - String系统相关的文件名。
append - boolean如果是
true ,那么数据将被写入文件的末尾而不是开头。
IOException - 如果命名文件存在,但是是一个目录而不是常规文件,不存在但不能创建,或由于任何其他原因无法打开
public FileWriter(File file) throws IOException
file - 要写入的File对象。
IOException - 如果文件存在但是是一个目录而不是常规文件,不存在但不能创建,或由于任何其他原因无法打开
public FileWriter(File file, boolean append) throws IOException
true ,则字节将写入文件的末尾而不是开头。
file - 要写入的File对象
append - 如果
true ,则字节将被写入文件的末尾而不是开头
IOException - 如果文件存在但是是一个目录而不是常规文件,则不存在但不能创建,或由于任何其他原因无法打开
public FileWriter(FileDescriptor fd)
fd - 要写入的FileDescriptor对象。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.