public class FileUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileUtil.StrictMode
Provides strict mode equivalents to methods in
FileUtil . |
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(java.io.Closeable closeable)
Closes the given
Closeable object ignoring any resulting exceptions. |
static boolean |
delete(java.io.File path)
Deletes a file or folder, even if the folder is not empty.
|
static boolean |
exists(java.lang.String path)
Checks if specified path points to a file or directory that exists on the local filesystem.
|
static java.io.File |
getExternalDirectory(android.content.Context context,
java.lang.String folderType,
java.lang.String name)
Gets the path to a directory on the primary shared/external storage device where the
application can place persistent files it owns.
|
static java.lang.String |
getFileName(java.lang.String url)
Gets the file name from a URL string.
|
static boolean |
hasFileScheme(java.net.URI uri)
Checks if the URI has a file scheme.
|
static boolean |
isDirectory(java.lang.String path)
Checks if specified path points to a directory that exists on the local filesystem.
|
static boolean |
isFile(java.lang.String path)
Checks if specified path points to a file that exists on the local filesystem.
|
static boolean |
isFileValid(java.io.File path)
Checks if the specified path is valid, meaning it exists or can be created, has read
permissions and has write permissions
|
static java.io.File |
makeReadWriteDirectory(java.io.File path)
Checks if the specified path is a directory that can be read from and written into.
|
static void |
saveInputStream(java.io.File target,
java.io.InputStream source)
Utility method to save the input stream to the file provided.
|
@NonNull public static java.io.File makeReadWriteDirectory(@Nullable java.io.File path)
path
- the path to check/create.java.lang.IllegalArgumentException
- if the download path is invalid or if the download path does
not have read or write permissions.public static boolean isFileValid(@Nullable java.io.File path)
path
- File to check if is valid.@NonNull public static java.io.File getExternalDirectory(@NonNull android.content.Context context, @Nullable java.lang.String folderType, @Nullable java.lang.String name)
Gets the path to a directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media.
Please note that this method will neither check if selected directory exists nor whether it is readable or writable.
context
- the contextfolderType
- the type of files directory to return. May be null for the root of the
files directory or one of the following constants for a subdirectory:
Environment.DIRECTORY_MUSIC
,
Environment.DIRECTORY_PODCASTS
,
Environment.DIRECTORY_RINGTONES
,
Environment.DIRECTORY_ALARMS
,
Environment.DIRECTORY_NOTIFICATIONS
,
Environment.DIRECTORY_PICTURES
, or
Environment.DIRECTORY_MOVIES
.name
- an optional subfolder name within the selected folder type.makeReadWriteDirectory(File)
public static boolean delete(@NonNull java.io.File path)
path
- the path to be deleted.public static java.lang.String getFileName(java.lang.String url)
url
- the url stringpublic static void closeQuietly(@Nullable java.io.Closeable closeable)
Closeable
object ignoring any resulting exceptions.closeable
- the object to be closed.public static void saveInputStream(@NonNull java.io.File target, @NonNull java.io.InputStream source) throws java.io.IOException
source
- the input streamtarget
- the file to save the input streamjava.io.IOException
- if the stream cannot be saved.public static boolean isFile(@Nullable java.lang.String path)
path
- the string path to be checked.public static boolean isDirectory(@Nullable java.lang.String path)
path
- the string path to be checked.public static boolean exists(@Nullable java.lang.String path)
path
- the string path to be checked.public static boolean hasFileScheme(java.net.URI uri)
uri
- the URI object to check.