Package com.tianscar.assetfile
Class AssetFile
java.lang.Object
com.tianscar.assetfile.AssetFile
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
ConstructorDescriptionAssetFile(android.net.Uri uri)
Creates a new AssetFile instance by converting the given file: Uri into an abstract pathname.Creates a new AssetFile instance from a parent abstract pathname and a child pathname string.Creates a new AssetFile instance by converting the given pathname string into an abstract pathname.Creates a new AssetFile instance from a parent pathname string and a child pathname string.Creates a new AssetFile instance by converting the given file: URI into an abstract pathname. -
Method Summary
Modifier and TypeMethodDescriptionint
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
Tests this abstract pathname for equality with the given object.boolean
exists()
Tests whether the file or directory denoted by this abstract pathname exists (in assets).getName()
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.getPath()
Converts this abstract pathname into a pathname string.int
hashCode()
Computes a hash code for this abstract pathname.boolean
Tests whether the file denoted by this abstract pathname is a directory.boolean
isFile()
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
length()
Returns the length of the file denoted by this abstract pathname.String[]
list()
Returns an array of strings naming the files (and directories if is root dir) in the directory denoted by this abstract pathname.String[]
list(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.Returns an array of abstract pathnames denoting the files (and directories if is root dir) in the directory denoted by this abstract pathname.listFiles(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.listFiles(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.mkdir(android.net.Uri parent)
Creates the directory from a parent Uri (into an abstract pathname) that copies all the files in the directory.Creates the directory from a parent abstract pathname that copies all the files in the directory.Creates the directory from a parent pathname string that copies all the files in the directory.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.Creates the directory from a parent abstract pathnamethat copies all the files in the directory, including any necessary but nonexistent parent directories.Creates the directory from a parent pathname string that copies all the files in the directory, including any necessary but nonexistent parent directories.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.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.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.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.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.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.toString()
Returns the pathname string of this abstract pathname.android.net.Uri
toUri()
Constructs a file:///android_asset/ Uri that represents this abstract pathname.toURI()
Constructs a file:///android_asset/ URI that represents this abstract pathname.toURL()
Deprecated.
-
Constructor Details
-
AssetFile
Creates a new AssetFile instance by converting the given pathname string into an abstract pathname.- Parameters:
pathname
- A pathname string
-
AssetFile
Creates a new AssetFile instance from a parent pathname string and a child pathname string.- Parameters:
parent
- The parent pathname stringchild
- The child pathname string
-
AssetFile
Creates a new AssetFile instance from a parent abstract pathname and a child pathname string.- Parameters:
parent
- The parent abstract pathnamechild
- 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
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
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
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
createNewFile
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
createNewFile
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
createNewFile
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the fileIllegalArgumentException
- 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 IOExceptionCreates 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 longsuffix
- The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be useddirectory
- 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 charactersIOException
- If a file could not be createdSecurityException
- 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 IOExceptionCreates 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 charactersIOException
- If a file could not be createdSecurityException
- 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
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
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
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
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
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. -
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. -
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
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
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
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
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
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
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdir
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdir
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdir
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdirs
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdirs
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdirs
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
mkdirs
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
-
renameTo
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
renameTo
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
renameTo
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 stringdest
- The pathname string- Returns:
- The file (or null if create failed)
- Throws:
IOException
- If an I/O error occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
renameTo
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 pathnamedest
- The abstract pathname string- Returns:
- The file (or null if create failed)
- Throws:
IOException
- If an I/O error occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
renameTo
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file
-
renameTo
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 occurredSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the fileIllegalArgumentException
- If the preconditions on the parameter do not hold
-
toString
Returns the pathname string of this abstract pathname. This is just the string returned by the getPath() method. -
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
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.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
-