Class File

java.lang.Object
com.mku.fs.file.File
All Implemented Interfaces:
IFile

public class File extends Object implements IFile
IFile implementation for a local file.
  • Field Details

    • separator

      public static final String separator
      Directory Separator
  • Constructor Details

    • File

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

    • createDirectory

      public IFile createDirectory(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(String filename) throws 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:
      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 String getDisplayPath()
      Get the display path on the physical disk.
      Specified by:
      getDisplayPath in interface IFile
      Returns:
      The display path.
    • getName

      public 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 FileNotFoundException
      Get a stream for reading the file.
      Specified by:
      getInputStream in interface IFile
      Returns:
      The stream to read from.
      Throws:
      FileNotFoundException - Thrown if file not found
    • getOutputStream

      public RandomAccessStream getOutputStream() throws FileNotFoundException
      Get a stream for writing to this file.
      Specified by:
      getOutputStream in interface IFile
      Returns:
      The stream to write to.
      Throws:
      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 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 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:
      IOException - Thrown if there is an IO error.
    • copy

      public IFile copy(IFile newDir, IFile.CopyOptions options) throws 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:
      IOException - Thrown if there is an IO error.
    • getChild

      public IFile getChild(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(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
    • getCredentials

      public Credentials getCredentials()
      Get the credentials
      Specified by:
      getCredentials in interface IFile
      Returns:
      The credentials
    • toString

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