Class File

  • All Implemented Interfaces:
    Serializable, Comparable<File>, IModifiable
    Direct Known Subclasses:
    Folder

    public class File
    extends File
    implements IModifiable
    Simple extension of File that adds an implementation of IModifiable for files. This allows the ModificationWatcher class to watch files for modification. The IModifiable.lastModifiedTime() method also returns a Time object with a more convenient API than either Date or a value in milliseconds.
    Author:
    Jonathan Locke
    See Also:
    Serialized Form
    • Constructor Detail

      • File

        public File​(File parent,
                    String child)
        Constructor.
        Parameters:
        parent - parent
        child - child
      • File

        public File​(File parent,
                    String child)
        Construct.
        Parameters:
        parent - parent
        child - child
      • File

        public File​(File file)
        Construct.
        Parameters:
        file - File from java.io package
      • File

        public File​(String pathname)
        Constructor.
        Parameters:
        pathname - path name
      • File

        public File​(String parent,
                    String child)
        Constructor.
        Parameters:
        parent - parent
        child - child
      • File

        public File​(URI uri)
        Constructor.
        Parameters:
        uri - file uri
    • Method Detail

      • file

        public File file​(String name)
        Parameters:
        name - Name of child file
        Returns:
        Child file object
      • getExtension

        public String getExtension()
        Returns:
        File extension (whatever is after the last '.' in the file name)
      • getParentFolder

        public Folder getParentFolder()
        Returns:
        Parent folder
      • lastModifiedTime

        public Instant lastModifiedTime()
        Returns a Time object representing the most recent time this file was modified.
        Specified by:
        lastModifiedTime in interface IModifiable
        Returns:
        This file's lastModified() value as a Time object or null if that information is not available
      • outputStream

        public OutputStream outputStream()
                                  throws FileNotFoundException
        Creates a buffered output stream that writes to this file. If the parent folder does not yet exist, creates all necessary folders in the path.
        Returns:
        Output stream that writes to this file
        Throws:
        FileNotFoundException - Thrown if the file cannot be found
      • remove

        public boolean remove()
        Returns:
        True if the file was removed
        See Also:
        File.delete()
      • toQuotedString

        public String toQuotedString()
        Returns:
        This file in double quotes (useful for passing to commands and tools that have issues with spaces in filenames)
      • write

        public int write​(File file)
                  throws IOException
        Writes the given file to this one
        Parameters:
        file - The file to copy
        Returns:
        number of bytes written
        Throws:
        IOException
      • write

        public int write​(InputStream input)
                  throws IOException
        Writes the given input stream to this file
        Parameters:
        input - The input
        Returns:
        Number of bytes written
        Throws:
        IOException
      • write

        public void write​(String string)
                   throws IOException
        Write the given string to this file
        Parameters:
        string - The string to write
        Throws:
        IOException