Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public final class FileUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static File |
checkIsDirectory(File directory)
Ensures that the file is a directory.
|
static boolean |
contentEquals(File file,
byte[] contents)
Compares the contents of a file to the provided array.
|
static boolean |
contentEquals(File file1,
File file2)
Compares the contents of two files, not supporting directories.
|
static int |
contentHashCode(File file)
Computes a hash code of the file contents, consistent with Arrays.hashCode(byte[]).
|
static long |
copy(File from,
Appendable out)
Copies a file to an appendable in system default locale.
|
static long |
copy(File from,
File to)
Copies one file over another, possibly creating if needed.
|
static long |
copy(File from,
OutputStream out)
Copies a file to an output stream.
|
static long |
copy(File from,
Writer out)
Copies a file to a writer in system default locale.
|
static void |
copyRecursive(File from,
File to)
Recursively copies source to destination.
|
static void |
copyRecursive(File from,
File to,
FileFilter fileFilter)
Recursively copies source to destination.
|
static File |
copyToTempFile(InputStream in,
String prefix,
String suffix)
Copies a stream to a newly created temporary file.
|
static File |
copyToTempFile(InputStream in,
String prefix,
String suffix,
File directory)
Copies a stream to a newly created temporary file.
|
static File |
createTempDirectory(String prefix,
String suffix)
Creates a temporary directory.
|
static File |
createTempDirectory(String prefix,
String suffix,
File directory)
Creates a temporary directory.
|
static void |
delete(File file)
Deletes the provided file, throwing IOException if unsuccessful.
|
static void |
deleteRecursive(File file)
Recursively deletes the provided file, being careful to not follow symbolic links (but there are still unavoidable race conditions).
|
static String |
getExtension(String path)
Gets the extension from the path, not including any period.
|
static File |
getFile(URL url,
String urlEncoding,
boolean deleteOnExit)
Gets a File for a URL, retrieving the contents into a temporary file if needed.
|
static File |
mkdir(File directory)
Makes a directory.
|
static File |
mkdirs(File directory)
Makes a directory and all of its parents.
|
static String |
readFileAsString(File file)
Reads the contents of a File and returns as a String.
|
static void |
rename(File from,
File to)
Atomically renames one file to another, throwing IOException when unsuccessful.
|
static void |
renameAllowNonAtomic(File from,
File to)
Renames one file to another, throwing IOException when unsuccessful.
|
public static void delete(File file) throws IOException
IOExceptionpublic static void deleteRecursive(File file) throws IOException
IOExceptionpublic static boolean contentEquals(File file, byte[] contents) throws IOException
IOExceptionpublic static boolean contentEquals(File file1, File file2) throws IOException
IOExceptionpublic static int contentHashCode(File file) throws IOException
IOExceptionArrays.hashCode(byte[])public static File createTempDirectory(String prefix, String suffix) throws IOException
IOExceptionpublic static File createTempDirectory(String prefix, String suffix, File directory) throws IOException
IOExceptionpublic static File copyToTempFile(InputStream in, String prefix, String suffix) throws IOException
IOExceptionpublic static File copyToTempFile(InputStream in, String prefix, String suffix, File directory) throws IOException
IOExceptionpublic static File mkdir(File directory) throws IOException
IOException - if mkdir fails.public static File mkdirs(File directory) throws IOException
IOException - if mkdirs fails.public static File checkIsDirectory(File directory) throws IOException
IOException - if not a directorypublic static long copy(File from, File to) throws IOException
IOExceptionpublic static long copy(File from, OutputStream out) throws IOException
IOExceptionpublic static long copy(File from, Writer out) throws IOException
IOExceptionpublic static long copy(File from, Appendable out) throws IOException
IOExceptionpublic static void copyRecursive(File from, File to) throws IOException
IOExceptionpublic static void copyRecursive(File from, File to, FileFilter fileFilter) throws IOException
IOExceptionpublic static String getExtension(String path)
public static File getFile(URL url, String urlEncoding, boolean deleteOnExit) throws IOException
deleteOnExit - when true, any newly created temp file will be flagged for deleteRecursive of exitIOExceptionpublic static void rename(File from, File to) throws IOException
IOExceptionpublic static void renameAllowNonAtomic(File from, File to) throws IOException
When the delete or rename fails, will retry up to ten times with increasing delay between each attempt.
IOExceptionpublic static String readFileAsString(File file) throws IOException
IOExceptionCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.