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 voidappendUtf8(File file, CharSequence text) static voidCopies a file to another location.static voidCopies a file to another location.static voiddeleteDirRecursive(File dir) Deletes all files within the given directory recursively (including subdirectories).static booleanDeletes all files within the given directory recursively (including subdirectories).private static FiledeleteDirRecursiveInternal(File dir, boolean failFast) static Stringstatic Stringstatic Stringstatic byte[]static Stringstatic <T> TreadObject(File file) To read an object in a quick invalid input: '&' dirty way.static Stringstatic voidupdateChecksum(File file, Checksum checksum) static voidwriteBytes(File file, byte[] content) static voidwriteChars(File file, String charset, CharSequence text, boolean apppend) static voidwriteObject(File file, Object object) To store an object in a quick invalid input: '&' dirty way.static voidwriteUtf8(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:
IOExceptionClassNotFoundException
-
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)
-