Package org.zkoss.io

Class FileWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class FileWriter extends OutputStreamWriter
Convenience class for writing character files. Unlike java.io.FileWriter, where the default character encoding is used, it accepts different character encoding.
Since:
3.0.8
Author:
tomyeh
  • Constructor Details

    • FileWriter

      public FileWriter(String filename, String charset) throws IOException
      Constructs a FileWriter object given a file name.
      Parameters:
      filename - String The system-dependent filename.
      charset - the charset to decode the file, such as UTF-8. If null, UTF-8 is assumed.
      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
    • FileWriter

      public FileWriter(String filename, String charset, boolean append) throws IOException
      Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
      Parameters:
      filename - String The system-dependent filename.
      charset - the charset to decode the file, such as UTF-8. If null, UTF-8 is assumed.
      append - boolean if true, 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
    • FileWriter

      public FileWriter(File file, String charset) throws IOException
      Constructs a FileWriter object given a File object.
      Parameters:
      file - a File object to write to.
      charset - the charset to decode the file, such as UTF-8. If null, UTF-8 is assumed.
      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
    • FileWriter

      public FileWriter(File file, String charset, boolean append) throws IOException
      Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
      Parameters:
      file - a File object to write to
      charset - the charset to decode the file, such as UTF-8. If null, UTF-8 is assumed.
      append - if true, then bytes 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
    • FileWriter

      public FileWriter(FileDescriptor fd, String charset) throws IOException
      Constructs a FileWriter object associated with a file descriptor.
      Parameters:
      fd - FileDescriptor object to write to.
      charset - the charset to decode the file, such as UTF-8. If null, UTF-8 is assumed.
      Throws:
      IOException