Class AssetFile

java.lang.Object
com.tianscar.assetfile.AssetFile

public class AssetFile extends Object
A File-like class that provides an abstract representation of file and directory pathnames (in assets). Instances of the AssetFile class are immutable; that is, once created, the abstract pathname represented by a File object will never change.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AssetFile​(android.net.Uri uri)
    Creates a new AssetFile instance by converting the given file: Uri into an abstract pathname.
    AssetFile​(AssetFile parent, String child)
    Creates a new AssetFile instance from a parent abstract pathname and a child pathname string.
    AssetFile​(String pathname)
    Creates a new AssetFile instance by converting the given pathname string into an abstract pathname.
    AssetFile​(String parent, String child)
    Creates a new AssetFile instance from a parent pathname string and a child pathname string.
    AssetFile​(URI uri)
    Creates a new AssetFile instance by converting the given file: URI into an abstract pathname.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo​(AssetFile pathname)
    Compares two abstract pathnames lexicographically.
    createNewFile​(android.net.Uri parent)
    Atomically creates a new file that copies the assetFile 's data by its name and a parent Uri (into an abstract pathname) if and only if a file with this name does not yet exist.
    createNewFile​(File parent)
    Atomically creates a new file that copies the assetFile 's data by its name and a parent abstract pathname if and only if a file with this name does not yet exist.
    createNewFile​(String parent)
    Atomically creates a new file that copies the assetFile 's data by its name and a parent pathname string if and only if a file with this name does not yet exist.
    createNewFile​(URI parent)
    Atomically creates a new file that copies the assetFile 's data by its name and a parent URI (into an abstract pathname) if and only if a file with this name does not yet exist.
    static File
    createTempFile​(String prefix, String suffix, AssetFile file)
    Creates an new file that copies the given assetFile 's data in the default temporary-file directory, using the given prefix and suffix to generate its name.
    static File
    createTempFile​(String prefix, String suffix, File directory, AssetFile file)
    Creates a new file that copies the given assetFile 's data in the specified directory, using the given prefix and suffix strings to generate its name.
    boolean
    equals​(Object obj)
    Tests this abstract pathname for equality with the given object.
    boolean
    Tests whether the file or directory denoted by this abstract pathname exists (in assets).
    Returns the name of the file or directory denoted by this abstract pathname.
    Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
    Converts this abstract pathname into a pathname string.
    int
    Computes a hash code for this abstract pathname.
    boolean
    Tests whether the file denoted by this abstract pathname is a directory.
    boolean
    Tests whether the file denoted by this abstract pathname is a file.
    boolean
    Tests whether the directory denoted by this abstract pathname is the assets root dir.
    int
    Returns the length of the file denoted by this abstract pathname.
    Returns an array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname.
    Returns an array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter.
    Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname.
    Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter.
    Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter.
    mkdir​(android.net.Uri parent)
    Creates the directory from a parent Uri (into an abstract pathname) that copies all the files in the directory.
    mkdir​(File parent)
    Creates the directory from a parent abstract pathname that copies all the files in the directory.
    mkdir​(String parent)
    Creates the directory from a parent pathname string that copies all the files in the directory.
    mkdir​(URI parent)
    Creates the directory from a parent URI (into an abstract pathname) that copies all the files in the directory.
    mkdirs​(android.net.Uri parent)
    Creates the directory from a parent Uri (into an abstract pathname) that copies all the files in the directory, including any necessary but nonexistent parent directories.
    mkdirs​(File parent)
    Creates the directory from a parent abstract pathnamethat copies all the files in the directory, including any necessary but nonexistent parent directories.
    mkdirs​(String parent)
    Creates the directory from a parent pathname string that copies all the files in the directory, including any necessary but nonexistent parent directories.
    mkdirs​(URI parent)
    Creates the directory from a parent URI (into an abstract pathname) that copies all the files in the directory, including any necessary but nonexistent parent directories.
    renameTo​(android.net.Uri dest)
    Atomically creates a new file that copies the assetFile 's data by the given URI (into an abstract pathname) if and only if a file with this name does not yet exist.
    renameTo​(File dest)
    Atomically creates a new file that copies the assetFile 's data by the given abstract pathname if and only if a file with this name does not yet exist.
    renameTo​(File parent, String dest)
    Atomically creates a new file that copies the assetFile 's data by the given pathname and a parent abstract pathname if and only if a file with this name does not yet exist.
    renameTo​(String dest)
    Atomically creates a new file that copies the assetFile 's data by the given pathname string into an abstract pathname if and only if a file with this name does not yet exist.
    renameTo​(String parent, String dest)
    Atomically creates a new file that copies the assetFile 's data by the given pathname and a parent pathname string if and only if a file with this name does not yet exist.
    renameTo​(URI dest)
    Atomically creates a new file that copies the assetFile 's data by the given URI (into an abstract pathname) if and only if a file with this name does not yet exist.
    Returns the pathname string of this abstract pathname.
    android.net.Uri
    Constructs a file:///android_asset/ Uri that represents this abstract pathname.
    Constructs a file:///android_asset/ URI that represents this abstract pathname.
    Deprecated.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AssetFile

      public AssetFile(@NonNull String pathname)
      Creates a new AssetFile instance by converting the given pathname string into an abstract pathname.
      Parameters:
      pathname - A pathname string
    • AssetFile

      public AssetFile(@NonNull String parent, @NonNull String child)
      Creates a new AssetFile instance from a parent pathname string and a child pathname string.
      Parameters:
      parent - The parent pathname string
      child - The child pathname string
    • AssetFile

      public AssetFile(@NonNull AssetFile parent, @NonNull String child)
      Creates a new AssetFile instance from a parent abstract pathname and a child pathname string.
      Parameters:
      parent - The parent abstract pathname
      child - The child pathname string
    • AssetFile

      public AssetFile(@NonNull android.net.Uri uri)
      Creates a new AssetFile instance by converting the given file: Uri into an abstract pathname.
      Parameters:
      uri - Uri: An absolute, hierarchical Uri with a non-empty path component, and undefined authority, query, and fragment components
      Throws:
      IllegalArgumentException - If the preconditions on the parameter do not hold
    • AssetFile

      public AssetFile(@NonNull URI uri)
      Creates a new AssetFile instance by converting the given file: URI into an abstract pathname.
      Parameters:
      uri - URI: An absolute, hierarchical URI with a scheme equal to "file" and a scheme specific part starts with "///android_asset/" a non-empty path component, and undefined authority, query, and fragment components
      Throws:
      IllegalArgumentException - If the preconditions on the parameter do not hold
  • Method Details

    • compareTo

      public int compareTo(@NonNull AssetFile pathname)
      Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. Alphabetic case is significant in comparing pathnames.
      Parameters:
      pathname - The abstract pathname to be compared to this abstract pathname
      Returns:
      Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument
    • createNewFile

      @Nullable public File createNewFile(@NonNull String parent) throws IOException
      Atomically creates a new file that copies the assetFile 's data by its name and a parent pathname string if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent pathname string
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • createNewFile

      @Nullable public File createNewFile(@NonNull File parent) throws IOException
      Atomically creates a new file that copies the assetFile 's data by its name and a parent abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent abstract pathname
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • createNewFile

      @Nullable public File createNewFile(@NonNull android.net.Uri parent) throws IOException
      Atomically creates a new file that copies the assetFile 's data by its name and a parent Uri (into an abstract pathname) if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent uri - an absolute, valid android Uri that can be converted to path
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • createNewFile

      @Nullable public File createNewFile(@NonNull URI parent) throws IOException
      Atomically creates a new file that copies the assetFile 's data by its name and a parent URI (into an abstract pathname) if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent URI - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
      IllegalArgumentException - If the preconditions on the parameter do not hold
    • createTempFile

      @NonNull public static File createTempFile(@NonNull String prefix, @Nullable String suffix, @Nullable File directory, @NonNull AssetFile file) throws IOException
      Creates a new file that copies the given assetFile 's data in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that: The file denoted by the returned abstract pathname did not exist before this method was invoked, and Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine. This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the deleteOnExit() method. The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used. To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix. If the directory argument is null then the system-dependent default temporary-file directory will be used. The default temporary-file directory is specified by the system property java.io.tmpdir. The default value of this property is typically "/tmp" or "/var/tmp"
      Parameters:
      prefix - The prefix string to be used in generating the file's name; must be at least three characters long
      suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
      directory - The directory in which the file is to be created, or null if the default temporary-file directory is to be used
      Returns:
      An abstract pathname denoting a newly-created empty file
      Throws:
      IllegalArgumentException - If the prefix argument contains fewer than three characters
      IOException - If a file could not be created
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • createTempFile

      @NonNull public static File createTempFile(@NonNull String prefix, @Nullable String suffix, @NonNull AssetFile file) throws IOException
      Creates an new file that copies the given assetFile 's data in the default temporary-file directory, using the given prefix and suffix to generate its name. Invoking this method is equivalent to invoking createTempFile(prefix, suffix, null). The Files.createTempFile method provides an alternative method to create an empty file in the temporary-file directory. Files created by that method may have more restrictive access permissions to files created by this method and so may be more suited to security-sensitive applications.
      Returns:
      An abstract pathname denoting a newly-created empty file
      Throws:
      IllegalArgumentException - If the prefix argument contains fewer than three characters
      IOException - If a file could not be created
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • exists

      public boolean exists()
      Tests whether the file or directory denoted by this abstract pathname exists (in assets).
      Returns:
      true if and only if the file or directory denoted by this abstract pathname exists (in assets); false otherwise
    • getName

      @NonNull public String getName()
      Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.
      Returns:
      The name of the file or directory denoted by this abstract pathname, or the empty string if this pathname's name sequence is empty
    • getParent

      @Nullable public String getParent()
      Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory. The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
      Returns:
      The pathname string of the parent directory named by this abstract pathname, or null if this pathname does not name a parent
    • getParentFile

      @Nullable public AssetFile getParentFile()
      Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory. The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
      Returns:
      The abstract pathname of the parent directory named by this abstract pathname, or null if this pathname does not name a parent
    • getPath

      @NonNull public String getPath()
      Converts this abstract pathname into a pathname string. The resulting string uses the default name-separator character to separate the names in the name sequence.
      Returns:
      The string form of this abstract pathname
    • equals

      public boolean equals(Object obj)
      Tests this abstract pathname for equality with the given object. Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname.
      Overrides:
      equals in class Object
      Parameters:
      obj - - Object: The object to be compared with this abstract pathname
      Returns:
      true if and only if the objects are the same; false otherwise
    • hashCode

      public int hashCode()
      Computes a hash code for this abstract pathname. The hash code of an abstract pathname is equal to the exclusive or of the hash code of its pathname string and the decimal value 1234321.
      Overrides:
      hashCode in class Object
      Returns:
      A hash code for this abstract pathname
    • isRootDir

      public boolean isRootDir()
      Tests whether the directory denoted by this abstract pathname is the assets root dir.
      Returns:
      true if and only if the directory is the assets root dir; false otherwise
    • isDirectory

      public boolean isDirectory()
      Tests whether the file denoted by this abstract pathname is a directory.
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
    • isFile

      public boolean isFile()
      Tests whether the file denoted by this abstract pathname is a file.
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is a file; false otherwise
    • length

      public int length()
      Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory. Where it is required to distinguish an I/O exception from the case that 0 is returned.
      Returns:
      The length, in bytes, of the file denoted by this abstract pathname, or 0 if the file does not exist.
    • list

      @Nullable public String[] list()
      Returns an array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of strings is returned, one for each file (and directories if is root dir) in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path. There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
      Returns:
      An array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
    • list

      @Nullable public String[] list(@Nullable AssetFilenameFilter filter)
      Returns an array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the list() method, except that the strings in the returned array must satisfy the filter. If the given filter is null then all names are accepted. Otherwise, a name satisfies the filter if and only if the value true results when the FilenameFilter#accept method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.
      Parameters:
      filter - An asset filename filter
      Returns:
      An array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname that were accepted by the given filter. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
    • listFiles

      @Nullable public AssetFile[] listFiles()
      Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of AssetFile objects is returned, one for each file (or directory if is root dir) in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting pathname is relative to the assets root dir. There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
      Returns:
      An array abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
    • listFiles

      @Nullable public AssetFile[] listFiles(@Nullable AssetFileFilter filter)
      Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the value true results when the AssetFileFilter#accept method of the filter is invoked on the pathname.
      Parameters:
      filter - An asset file filter
      Returns:
      An array abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
    • listFiles

      @Nullable public AssetFile[] listFiles(@Nullable AssetFilenameFilter filter)
      Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the value true results when the FilenameFilter#accept method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.
      Parameters:
      filter - An asset filename filter
      Returns:
      An array abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
    • mkdir

      @Nullable public File mkdir(@NonNull String parent) throws IOException
      Creates the directory from a parent pathname string that copies all the files in the directory.
      Parameters:
      parent - The parent pathname string
      Returns:
      The directory if and only if the directory was created; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdir

      @Nullable public File mkdir(@NonNull File parent) throws IOException
      Creates the directory from a parent abstract pathname that copies all the files in the directory.
      Parameters:
      parent - The parent abstract pathname
      Returns:
      The directory if and only if the directory was created; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdir

      @Nullable public File mkdir(@NonNull android.net.Uri parent) throws IOException
      Creates the directory from a parent Uri (into an abstract pathname) that copies all the files in the directory.
      Parameters:
      parent - The parent uri - an absolute, valid android Uri that can be converted to path
      Returns:
      The directory if and only if the directory was created; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdir

      @Nullable public File mkdir(@NonNull URI parent) throws IOException
      Creates the directory from a parent URI (into an abstract pathname) that copies all the files in the directory.
      Parameters:
      parent - The parent URI - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
      Returns:
      The directory if and only if the directory was created; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdirs

      @Nullable public File mkdirs(@NonNull String parent) throws IOException
      Creates the directory from a parent pathname string that copies all the files in the directory, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
      Parameters:
      parent - The parent pathname string
      Returns:
      The directory if and only if the directory was created, along with all necessary parent directories; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdirs

      @Nullable public File mkdirs(@NonNull File parent) throws IOException
      Creates the directory from a parent abstract pathnamethat copies all the files in the directory, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
      Parameters:
      parent - The parent abstract pathname
      Returns:
      The directory if and only if the directory was created, along with all necessary parent directories; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdirs

      @Nullable public File mkdirs(@NonNull android.net.Uri parent) throws IOException
      Creates the directory from a parent Uri (into an abstract pathname) that copies all the files in the directory, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
      Parameters:
      parent - The parent uri - an absolute, valid android Uri that can be converted to path
      Returns:
      The directory if and only if the directory was created, along with all necessary parent directories; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • mkdirs

      @Nullable public File mkdirs(@NonNull URI parent) throws IOException
      Creates the directory from a parent URI (into an abstract pathname) that copies all the files in the directory, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
      Parameters:
      parent - The parent URI - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
      Returns:
      The directory if and only if the directory was created, along with all necessary parent directories; null otherwise
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
    • renameTo

      @Nullable public File renameTo(@NonNull File dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      dest - The abstract pathname
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • renameTo

      @Nullable public File renameTo(@NonNull String dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given pathname string into an abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      dest - The pathname string
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • renameTo

      @Nullable public File renameTo(@NonNull String parent, @NonNull String dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given pathname and a parent pathname string if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent pathname string
      dest - The pathname string
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • renameTo

      @Nullable public File renameTo(@NonNull File parent, @NonNull String dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given pathname and a parent abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      parent - The parent abstract pathname
      dest - The abstract pathname string
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • renameTo

      @Nullable public File renameTo(@NonNull android.net.Uri dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given URI (into an abstract pathname) if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      dest - An absolute, valid android Uri that can be converted to path
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
    • renameTo

      @Nullable public File renameTo(@NonNull URI dest) throws IOException
      Atomically creates a new file that copies the assetFile 's data by the given URI (into an abstract pathname) if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.
      Parameters:
      dest - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
      Returns:
      The file (or null if create failed)
      Throws:
      IOException - If an I/O error occurred
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
      IllegalArgumentException - If the preconditions on the parameter do not hold
    • toString

      @NonNull public String toString()
      Returns the pathname string of this abstract pathname. This is just the string returned by the getPath() method.
      Overrides:
      toString in class Object
      Returns:
      The string form of this abstract pathname
    • toUri

      @NonNull public android.net.Uri toUri()
      Constructs a file:///android_asset/ Uri that represents this abstract pathname. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URI will end with a slash.
      Returns:
      An absolute, hierarchical Uri with a scheme equal to "file" and a scheme specific part starts with "///android_asset/", a path representing this abstract pathname, and undefined authority, query, and fragment components
    • toURI

      @NonNull public URI toURI()
      Constructs a file:///android_asset/ URI that represents this abstract pathname. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URI will end with a slash.
      Returns:
      An absolute, hierarchical URI with a scheme equal to "file" and a scheme specific part starts with "///android_asset/", a path representing this abstract pathname, and undefined authority, query, and fragment components
    • toURL

      @Deprecated public URL toURL() throws MalformedURLException
      Deprecated.
      This method was deprecated. This method does not automatically escape characters that are illegal in URLs. It is recommended that new code convert an abstract pathname into a URL by first converting it into a URI, via the toURI method, and then converting the URI into a URL via the URI.toURL method. Converts this abstract pathname into a file:///android_asset/ URL. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URL will end with a slash.
      Returns:
      A URL object representing the equivalent file URL
      Throws:
      MalformedURLException - If the path cannot be parsed as a URL