Class File

  • All Implemented Interfaces:
    IFile

    public class File
    extends java.lang.Object
    implements IFile
    IFile implementation for a local file.
    • Field Detail

      • separator

        public static final java.lang.String separator
        Directory Separator
    • Constructor Detail

      • File

        public File​(java.lang.String path)
        Instantiate a real file represented by the filepath provided.
        Parameters:
        path - The filepath.
    • Method Detail

      • createDirectory

        public IFile createDirectory​(java.lang.String dirName)
        Create a directory under this directory.
        Specified by:
        createDirectory in interface IFile
        Parameters:
        dirName - The name of the new directory.
        Returns:
        The newly created directory.
      • createFile

        public IFile createFile​(java.lang.String filename)
                         throws java.io.IOException
        Create a file under this directory.
        Specified by:
        createFile in interface IFile
        Parameters:
        filename - The name of the new file.
        Returns:
        The newly created file.
        Throws:
        java.io.IOException - Thrown if there is an IO error.
      • delete

        public boolean delete()
        Delete this file or directory.
        Specified by:
        delete in interface IFile
        Returns:
        True if deletion is successful.
      • exists

        public boolean exists()
        Check if file or directory exists.
        Specified by:
        exists in interface IFile
        Returns:
        True if exists.
      • getDisplayPath

        public java.lang.String getDisplayPath()
        Get the display path on the physical disk.
        Specified by:
        getDisplayPath in interface IFile
        Returns:
        The display path.
      • getName

        public java.lang.String getName()
        Get the name of this file or directory.
        Specified by:
        getName in interface IFile
        Returns:
        The name of this file or directory.
      • getInputStream

        public RandomAccessStream getInputStream()
                                          throws java.io.FileNotFoundException
        Get a stream for reading the file.
        Specified by:
        getInputStream in interface IFile
        Returns:
        The stream to read from.
        Throws:
        java.io.FileNotFoundException - Thrown if file not found
      • getOutputStream

        public RandomAccessStream getOutputStream()
                                           throws java.io.FileNotFoundException
        Get a stream for writing to this file.
        Specified by:
        getOutputStream in interface IFile
        Returns:
        The stream to write to.
        Throws:
        java.io.FileNotFoundException - Thrown if file not found
      • getParent

        public IFile getParent()
        Get the parent directory of this file or directory.
        Specified by:
        getParent in interface IFile
        Returns:
        The parent directory.
      • getPath

        public java.lang.String getPath()
        Get the path of this file.
        Specified by:
        getPath in interface IFile
        Returns:
        The path
      • isDirectory

        public boolean isDirectory()
        Check if this is a directory.
        Specified by:
        isDirectory in interface IFile
        Returns:
        True if it's a directory.
      • isFile

        public boolean isFile()
        Check if this is a file.
        Specified by:
        isFile in interface IFile
        Returns:
        True if it's a file
      • getLastDateModified

        public long getLastDateModified()
        Get the last modified date on disk.
        Specified by:
        getLastDateModified in interface IFile
        Returns:
        The last modified date in milliseconds
      • getLength

        public long getLength()
        Get the size of the file on disk.
        Specified by:
        getLength in interface IFile
        Returns:
        The length
      • getChildrenCount

        public int getChildrenCount()
        Get the count of files and subdirectories
        Specified by:
        getChildrenCount in interface IFile
        Returns:
        The children count
      • listFiles

        public IFile[] listFiles()
        List all files under this directory.
        Specified by:
        listFiles in interface IFile
        Returns:
        The list of files.
      • move

        public IFile move​(IFile newDir)
        Move this file or directory under a new directory.
        Specified by:
        move in interface IFile
        Parameters:
        newDir - The target directory.
        Returns:
        The moved file. Use this file for subsequent operations instead of the original.
      • move

        public IFile move​(IFile newDir,
                          IFile.MoveOptions options)
        Move this file or directory under a new directory.
        Specified by:
        move in interface IFile
        Parameters:
        newDir - The target directory.
        options - The options
        Returns:
        The moved file. Use this file for subsequent operations instead of the original.
      • copy

        public IFile copy​(IFile newDir)
                   throws java.io.IOException
        Move this file or directory under a new directory.
        Specified by:
        copy in interface IFile
        Parameters:
        newDir - The target directory.
        Returns:
        The copied file. Use this file for subsequent operations instead of the original.
        Throws:
        java.io.IOException - Thrown if there is an IO error.
      • copy

        public IFile copy​(IFile newDir,
                          IFile.CopyOptions options)
                   throws java.io.IOException
        Move this file or directory under a new directory.
        Specified by:
        copy in interface IFile
        Parameters:
        newDir - The target directory.
        options - The options
        Returns:
        The copied file. Use this file for subsequent operations instead of the original.
        Throws:
        java.io.IOException - Thrown if there is an IO error.
      • getChild

        public IFile getChild​(java.lang.String filename)
        Get the file or directory under this directory with the provided name.
        Specified by:
        getChild in interface IFile
        Parameters:
        filename - The name of the file or directory.
        Returns:
        The child
      • renameTo

        public boolean renameTo​(java.lang.String newFilename)
        Rename the current file or directory.
        Specified by:
        renameTo in interface IFile
        Parameters:
        newFilename - The new name for the file or directory.
        Returns:
        True if successfully renamed.
      • mkdir

        public boolean mkdir()
        Create this directory under the current filepath.
        Specified by:
        mkdir in interface IFile
        Returns:
        True if created.
      • reset

        public void reset()
        Reset cached properties
        Specified by:
        reset in interface IFile
      • toString

        public java.lang.String toString()
        Returns a string representation of this object
        Overrides:
        toString in class java.lang.Object