-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
Copies a file to a writer in system default locale.static long
copy
(File from, Appendable out) Copies a file to an appendable 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 long
copyToFile
(InputStream in, File file) Copies a stream to a file.static File
copyToTempFile
(InputStream in, String prefix, String suffix) Copies a stream to a newly created temporary file in the given directory.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) Deprecated.static File
createTempDirectory
(String prefix, String suffix, File directory) Deprecated.Please useFiles.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute...)
, which does not suffer from any race conditions.static void
Deprecated.Please useFiles.delete(java.nio.file.Path)
static void
deleteRecursive
(File file) Deprecated.static String
getExtension
(String path) Gets the extension from the path, not including any period.static File
Deprecated.Please use TempFileContext asFile.deleteOnExit()
is prone to memory leaks in long-running applications.static File
Deprecated.static File
Deprecated.static String
readFileAsString
(File file) Reads the contents of a File and returns as a String in the system default character set.static String
readFileAsString
(File file, Charset charset) Reads the contents of a File and returns as a String in the provided character set.static void
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.
-
Method Details
-
delete
Deprecated.Please useFiles.delete(java.nio.file.Path)
Deletes the provided file, throwing IOException if unsuccessful.- Throws:
IOException
-
deleteRecursive
Deprecated.Recursively deletes the provided file, being careful to not follow symbolic links (but there are still unavoidable race conditions).- Throws:
IOException
-
contentEquals
Compares the contents of a file to the provided array.- Throws:
IOException
-
contentEquals
Compares the contents of two files, not supporting directories.- Throws:
IOException
-
contentHashCode
Computes a hash code of the file contents, consistent with Arrays.hashCode(byte[]).- Throws:
IOException
- See Also:
-
createTempDirectory
Deprecated.Please useFiles.createTempDirectory(java.lang.String, java.nio.file.attribute.FileAttribute...)
, which does not suffer from any race conditions.Creates a temporary directory.- Throws:
IOException
-
createTempDirectory
@Deprecated public static File createTempDirectory(String prefix, String suffix, File directory) throws IOException Deprecated.Please useFiles.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute...)
, which does not suffer from any race conditions.Creates a temporary directory.- Throws:
IOException
-
copyToFile
Copies a stream to a file.- Returns:
- the number of bytes copied
- Throws:
IOException
-
copyToTempFile
Copies a stream to a newly created temporary file in the given directory.The file is created with the default permissions via
Files.createTempFile(java.lang.String, java.lang.String, java.nio.file.attribute.FileAttribute...)
.The file is not deleted on exit. If this is required, we recommend creating the temp file with the AO TempFiles project, then using
copyToFile(java.io.InputStream, java.io.File)
. This avoids the memory leak of the implementation ofFile.deleteOnExit()
.- Throws:
IOException
-
copyToTempFile
public static File copyToTempFile(InputStream in, String prefix, String suffix, File directory) throws IOException Copies a stream to a newly created temporary file.The file is created with the default permissions via
Files.createTempFile(java.lang.String, java.lang.String, java.nio.file.attribute.FileAttribute...)
.The file is not deleted on exit. If this is required, we recommend creating the temp file with the AO TempFiles project, then using
copyToFile(java.io.InputStream, java.io.File)
. This avoids the memory leak of the implementation ofFile.deleteOnExit()
.- Throws:
IOException
-
mkdir
Deprecated.Makes a directory. The directory must not already exist.- Returns:
- The directory itself.
- Throws:
IOException
- if mkdir fails.
-
mkdirs
Deprecated.Makes a directory and all of its parents. The directory may optionally already exist.- Returns:
- The directory itself.
- Throws:
IOException
- if mkdirs fails.
-
checkIsDirectory
Ensures that the file is a directory.- Returns:
- The directory itself.
- Throws:
IOException
- if not a directory
-
copy
Copies one file over another, possibly creating if needed.- Returns:
- the number of bytes copied
- Throws:
IOException
-
copy
Copies a file to an output stream.- Returns:
- the number of bytes copied
- Throws:
IOException
-
copy
Copies a file to a writer in system default locale.- Returns:
- the number of characters copied
- Throws:
IOException
-
copy
Copies a file to an appendable in system default locale.- Returns:
- the number of characters copied
- Throws:
IOException
-
copyRecursive
Recursively copies source to destination. Destination must not exist.- Throws:
IOException
-
copyRecursive
Recursively copies source to destination. Destination must not exist.- Throws:
IOException
-
getExtension
Gets the extension from the path, not including any period. If no extension, returns an empty string. -
getFile
@Deprecated public static File getFile(URL url, String urlEncoding, boolean deleteOnExit) throws IOException Deprecated.Please use TempFileContext asFile.deleteOnExit()
is prone to memory leaks in long-running applications.Gets a File for a URL, retrieving the contents into a temporary file if needed.The file is created with the default permissions via
Files.createTempFile(java.lang.String, java.lang.String, java.nio.file.attribute.FileAttribute...)
.- Parameters:
deleteOnExit
- whentrue
, any newly created temp file will be flagged fordelete on exit
- Throws:
IOException
-
rename
Atomically renames one file to another, throwing IOException when unsuccessful.- Throws:
IOException
-
renameAllowNonAtomic
Renames one file to another, throwing IOException when unsuccessful. Allow a non-atomic delete/rename pair when the underlying system is unable to rename one file over another, such as in Microsoft Windows.- Throws:
IOException
-
readFileAsString
Reads the contents of a File and returns as a String in the system default character set.- Throws:
IOException
- See Also:
-
readFileAsString
Reads the contents of a File and returns as a String in the provided character set.- Throws:
IOException
- See Also:
-
Files.createTempDirectory(java.lang.String, java.nio.file.attribute.FileAttribute...)
, which does not suffer from any race conditions.