Class FileWriterWithName

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public final class FileWriterWithName extends FileWriter
Just like FileWriter, but adds a getFileName() method and overrides #toString() to give the file name.
  • Constructor Details

    • FileWriterWithName

      public FileWriterWithName(String fileName) throws IOException
      Constructs a FileWriterWithName object given a file name.
      Parameters:
      fileName - 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
    • FileWriterWithName

      public FileWriterWithName(String fileName, boolean append) throws IOException
      Constructs a FileWriterWithName object given a file name with a boolean indicating whether or not to append the data written.
      Parameters:
      fileName - the system-dependent filename
      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
    • FileWriterWithName

      public FileWriterWithName(File file) throws IOException
      Constructs a FileWriterWithName object given a File object.
      Parameters:
      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
    • FileWriterWithName

      public FileWriterWithName(File file, boolean append) throws IOException
      Constructs a FileWriterWithName 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
      append - if true, 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
  • Method Details

    • getFileName

      @Pure public String getFileName(@GuardedByUnknown FileWriterWithName this)
      Returns the name of the file being written by this.
      Returns:
      the name of the file being written by this
    • toString

      @Pure public String toString(@GuardedByUnknown FileWriterWithName this)
      Returns the name of the file being written by this.
      Overrides:
      toString in class Object
      Returns:
      the name of the file being written by this