-
public class FileUtil
Provides utility methods to work files and folders.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
FileUtil.StrictMode
Provides strict mode equivalents to methods in FileUtil. Strict mode methods will beexecuted in an io thread, blocking the calling thread until the operation is complete.
-
Method Summary
Modifier and Type Method Description static File
makeReadWriteDirectory(@Nullable() File path)
Checks if the specified path is a directory that can be read from and written into. static boolean
isFileValid(@Nullable() File path)
Checks if the specified path is valid, meaning it exists or can be created, has readpermissions and has write permissions static File
getExternalDirectory(@NonNull() Context context, @Nullable() String folderType, @Nullable() String name)
Gets the path to a directory on the primary shared/external storage device where theapplication can place persistent files it owns. static boolean
delete(@NonNull() File path)
Deletes a file or folder, even if the folder is not empty. static String
getFileName(String url)
Gets the file name from a URL string. static void
closeQuietly(@Nullable() Closeable closeable)
Closes the given Closeable object ignoring any resulting exceptions. static void
saveInputStream(@NonNull() File target, @NonNull() InputStream source)
Utility method to save the input stream to the file provided. static boolean
isFile(@Nullable() String path)
Checks if specified path points to a file that exists on the local filesystem. static boolean
isDirectory(@Nullable() String path)
Checks if specified path points to a directory that exists on the local filesystem. static boolean
exists(@Nullable() String path)
Checks if specified path points to a file or directory that exists on the local filesystem. static boolean
hasFileScheme(URI uri)
Checks if the URI has a file scheme. -
-
Method Detail
-
makeReadWriteDirectory
@NonNull() static File makeReadWriteDirectory(@Nullable() File path)
Checks if the specified path is a directory that can be read from and written into. If thedirectory does not exist, then this method will try to create a readable/writable directory.
- Parameters:
path
- the path to check/create.
-
isFileValid
static boolean isFileValid(@Nullable() File path)
Checks if the specified path is valid, meaning it exists or can be created, has readpermissions and has write permissions
- Parameters:
path
- File to check if is valid.
-
getExternalDirectory
@NonNull() static File getExternalDirectory(@NonNull() Context context, @Nullable() String folderType, @Nullable() String name)
Gets the path to a directory on the primary shared/external storage device where theapplication 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 whetherit is readable or writable.
- Parameters:
context
- the contextfolderType
- the type of files directory to return.name
- an optional subfolder name within the selected folder type.
-
delete
static boolean delete(@NonNull() File path)
Deletes a file or folder, even if the folder is not empty.
- Parameters:
path
- the path to be deleted.
-
getFileName
static String getFileName(String url)
Gets the file name from a URL string.
- Parameters:
url
- the url string
-
closeQuietly
static void closeQuietly(@Nullable() Closeable closeable)
Closes the given Closeable object ignoring any resulting exceptions.
- Parameters:
closeable
- the object to be closed.
-
saveInputStream
static void saveInputStream(@NonNull() File target, @NonNull() InputStream source)
Utility method to save the input stream to the file provided.
- Parameters:
target
- the file to save the input streamsource
- the input stream
-
isFile
static boolean isFile(@Nullable() String path)
Checks if specified path points to a file that exists on the local filesystem.
- Parameters:
path
- the string path to be checked.
-
isDirectory
static boolean isDirectory(@Nullable() String path)
Checks if specified path points to a directory that exists on the local filesystem.
- Parameters:
path
- the string path to be checked.
-
exists
static boolean exists(@Nullable() String path)
Checks if specified path points to a file or directory that exists on the local filesystem.
- Parameters:
path
- the string path to be checked.
-
hasFileScheme
static boolean hasFileScheme(URI uri)
Checks if the URI has a file scheme.
- Parameters:
uri
- the URI object to check.
-
-
-
-