Class FileLocation

All Implemented Interfaces:
Serializable, Location<String>

public class FileLocation extends AbstractLocation<String>
Wrapper for manipulating a file. This implementation of the Location interface allows writing to and reading from a file.
Author:
Laurent Cohen
See Also:
  • Constructor Details

    • FileLocation

      public FileLocation(File file) throws IOException
      Initialize this location with the specified file path.

      Warning: if this file location is intended for use on a remote machine, then you should use FileLocation(String) instead, since this constructor computes the path as the system-dependent canonical path of the argument.

      Parameters:
      file - an abstract file path.
      Throws:
      IOException - if any I/O error occurs.
    • FileLocation

      public FileLocation(String file)
      Initialize this location with the specified file path.
      Parameters:
      file - a string representing the file path.
  • Method Details

    • getInputStream

      public InputStream getInputStream() throws Exception
      Description copied from interface: Location
      Obtain an input stream to read from this location.
      Returns:
      an InputStream instance.
      Throws:
      Exception - if an I/O error occurs.
    • getOutputStream

      public OutputStream getOutputStream() throws Exception
      Description copied from interface: Location
      Obtain an output stream to write to this location.
      Returns:
      an OutputStream instance.
      Throws:
      Exception - if an I/O error occurs.
    • size

      public long size()
      Get the size of the file this location points to.
      Returns:
      the size as a long value, or -1 if the file does not exist.