-
Method Summary
Modifier and TypeMethodDescriptionstatic FilecheckIsDirectory(File directory) Ensures that the file is a directory.static booleancontentEquals(File file, byte[] contents) Compares the contents of a file to the provided array.static booleancontentEquals(File file1, File file2) Compares the contents of two files, not supporting directories.static intcontentHashCode(File file) Computes a hash code of the file contents, consistent with Arrays.hashCode(byte[]).static longCopies one file over another, possibly creating if needed.static longcopy(File from, OutputStream out) Copies a file to an output stream.static longCopies a file to a writer in system default locale.static longcopy(File from, Appendable out) Copies a file to an appendable in system default locale.static voidcopyRecursive(File from, File to) Recursively copies source to destination.static voidcopyRecursive(File from, File to, FileFilter fileFilter) Recursively copies source to destination.static longcopyToFile(InputStream in, File file) Copies a stream to a file.static FilecopyToTempFile(InputStream in, String prefix, String suffix) Copies a stream to a newly created temporary file in the given directory.static FilecopyToTempFile(InputStream in, String prefix, String suffix, File directory) Copies a stream to a newly created temporary file.static FilecreateTempDirectory(String prefix, String suffix) Deprecated.static FilecreateTempDirectory(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 voidDeprecated.Please useFiles.delete(java.nio.file.Path)static voiddeleteRecursive(File file) Deprecated.static StringgetExtension(String path) Gets the extension from the path, not including any period.static FileDeprecated.Please use TempFileContext asFile.deleteOnExit()is prone to memory leaks in long-running applications.static FileDeprecated.static FileDeprecated.static StringreadFileAsString(File file) Reads the contents of a File and returns as a String in the system default character set.static StringreadFileAsString(File file, Charset charset) Reads the contents of a File and returns as a String in the provided character set.static voidAtomically renames one file to another, throwing IOException when unsuccessful.static voidrenameAllowNonAtomic(File from, File to) Renames one file to another, throwing IOException when unsuccessful.static voidsetLastModified(File file, long time) Sets the last modified, 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
-
setLastModified
Sets the last modified, throwing IOException when unsuccessful.- Throws:
IOException
-
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.