Class AndroidFile

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

public class AndroidFile extends Object implements IFile
Implementation of the IFile for Android using Storage Access Framework that supports read/write to external SD cards. This class is used by the AndroidDrive implementation so you can use AesFile wrapper transparently
  • Field Details

  • Constructor Details

    • AndroidFile

      public AndroidFile(DocumentFile documentFile)
      Construct an AndroidFile wrapper from an Android DocumentFile.
      Parameters:
      documentFile - The Android DocumentFile that will be associated to
    • AndroidFile

      protected AndroidFile(DocumentFile documentFile, AndroidFile parent)
      Construct an AndroidFile wrapper from an Android DocumentFile.
      Parameters:
      documentFile - The Android DocumentFile that will be associated to
      parent - The parent if available
    • AndroidFile

      protected AndroidFile(AndroidFile parent, String name)
      Construct an AndroidFile.
      Parameters:
      parent - The parent file.
      name - The file name.
  • Method Details

    • createDirectory

      public IFile createDirectory(String dirName)
      Create a directory under this directory.
      Specified by:
      createDirectory in interface IFile
      Parameters:
      dirName - The directory name.
      Returns:
      The new directory.
    • createFile

      public IFile createFile(String filename)
      Create an empty file under this directory.
      Specified by:
      createFile in interface IFile
      Parameters:
      filename - The file name.
      Returns:
      The new file.
    • delete

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

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

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

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

      public RandomAccessStream getInputStream() throws FileNotFoundException
      Get a stream for reading.
      Specified by:
      getInputStream in interface IFile
      Returns:
      The input stream
      Throws:
      FileNotFoundException - Thrown if file is not found
    • getOutputStream

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

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

      public String getPath()
      Get the path on the physical disk.
      Specified by:
      getPath in interface IFile
      Returns:
      The file path
    • isDirectory

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

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

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

      public long getLength()
      Get the size of the file.
      Specified by:
      getLength in interface IFile
      Returns:
      The size
    • 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 files and directories.
      Specified by:
      listFiles in interface IFile
      Returns:
      The files and subdirectories
    • move

      public IFile move(IFile newDir) throws IOException
      Move this file to another directory.
      Specified by:
      move in interface IFile
      Parameters:
      newDir - The target directory.
      Returns:
      The moved file
      Throws:
      IOException - Thrown if error during IO
    • move

      public IFile move(IFile newDir, IFile.MoveOptions options) throws IOException
      Move this file to another directory.
      Specified by:
      move in interface IFile
      Parameters:
      newDir - The target directory.
      options - The options.
      Returns:
      The moved file
      Throws:
      IOException - Thrown if error during IO
    • copy

      public IFile copy(IFile newDir) throws IOException
      Copy this file to another directory.
      Specified by:
      copy in interface IFile
      Parameters:
      newDir - The target directory.
      Returns:
      The new file
      Throws:
      IOException - Thrown if error during IO
    • copy

      public IFile copy(IFile newDir, IFile.CopyOptions options) throws IOException
      Copy this file to another directory with a new filename with a progress.
      Specified by:
      copy in interface IFile
      Parameters:
      newDir - The target directory.
      options - The options
      Returns:
      The new file
      Throws:
      IOException - Thrown if error during IO
    • getChild

      public IFile getChild(String filename)
      Get a child file or directory under this directory.
      Specified by:
      getChild in interface IFile
      Parameters:
      filename - The name of the file or directory to match.
      Returns:
      The child file
    • renameTo

      public boolean renameTo(String newFilename) throws FileNotFoundException
      Rename this file.
      Specified by:
      renameTo in interface IFile
      Parameters:
      newFilename - The new filename
      Returns:
      True if file renamed
      Throws:
      FileNotFoundException - Thrown if file is not found
    • mkdir

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

      public void reset()
      Clear cache properties.
      Specified by:
      reset in interface IFile
    • getCredentials

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

      public ParcelFileDescriptor getFileDescriptor(String mode) throws FileNotFoundException
      Get a file descriptor corresponding to this file.
      Parameters:
      mode - The mode
      Returns:
      The parcel file descriptor
      Throws:
      FileNotFoundException - Thrown if file is not found
    • toString

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