Package org.greenrobot.essentials.io
Class FileUtils
java.lang.Object
org.greenrobot.essentials.io.FileUtils
Utils for dealing with files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendUtf8
(File file, CharSequence text) static void
Copies a file to another location.static void
Copies a file to another location.static void
deleteDirRecursive
(File dir) Deletes all files within the given directory recursively (including subdirectories).static boolean
Deletes all files within the given directory recursively (including subdirectories).private static File
deleteDirRecursiveInternal
(File dir, boolean failFast) static String
static String
static String
static byte[]
static String
static <T> T
readObject
(File file) To read an object in a quick invalid input: '&' dirty way.static String
static void
updateChecksum
(File file, Checksum checksum) static void
writeBytes
(File file, byte[] content) static void
writeChars
(File file, String charset, CharSequence text, boolean apppend) static void
writeObject
(File file, Object object) To store an object in a quick invalid input: '&' dirty way.static void
writeUtf8
(File file, CharSequence text)
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
readBytes
- Throws:
IOException
-
writeBytes
- Throws:
IOException
-
readUtf8
- Throws:
IOException
-
readChars
- Throws:
IOException
-
writeUtf8
- Throws:
IOException
-
appendUtf8
- Throws:
IOException
-
writeChars
public static void writeChars(File file, String charset, CharSequence text, boolean apppend) throws IOException - Throws:
IOException
-
copyFile
Copies a file to another location.- Throws:
IOException
-
copyFile
Copies a file to another location.- Throws:
IOException
-
readObject
To read an object in a quick invalid input: '&' dirty way. Prepare to handle failures when object serialization changes!- Throws:
IOException
ClassNotFoundException
-
writeObject
To store an object in a quick invalid input: '&' dirty way.- Throws:
IOException
-
getMd5
- Returns:
- MD5 digest (32 hex characters).
- Throws:
IOException
-
getSha1
- Returns:
- SHA-1 digest (40 hex characters).
- Throws:
IOException
-
getSha256
- Returns:
- SHA-256 digest (64 hex characters).
- Throws:
IOException
-
updateChecksum
- Throws:
IOException
-
deleteDirRecursive
Deletes all files within the given directory recursively (including subdirectories). This method fails fast with an IOException on the first file that could not be deleted.- Throws:
IOException
-
deleteDirRecursiveBestEffort
Deletes all files within the given directory recursively (including subdirectories). It will try to delete as many files as possible (best effort) and will not fail on files that couldn't be deleted.- Returns:
- true if the given dir does not exist anymore on completion of this method
-
deleteDirRecursiveInternal
- Returns:
- File that could not be deleted (fail fast mode only)
-