Package jodd.io
Class FileUtil
- java.lang.Object
-
- jodd.io.FileUtil
-
public class FileUtil extends java.lang.ObjectFile utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringtempFilePrefixDefault prefix for temporary files.
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidappendBytes(java.io.File dest, byte[] data)static voidappendBytes(java.io.File dest, byte[] data, int off, int len)Appends bytes.static voidappendBytes(java.lang.String dest, byte[] data)static voidappendBytes(java.lang.String dest, byte[] data, int off, int len)static voidappendString(java.io.File dest, java.lang.String data)static voidappendString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding)Appends String.static voidappendString(java.lang.String dest, java.lang.String data)static voidappendString(java.lang.String dest, java.lang.String data, java.nio.charset.Charset encoding)static voidcleanDir(java.io.File destDir)Cleans a directory without deleting it.static voidcleanDir(java.lang.String dest)static booleancompare(java.io.File one, java.io.File two)Compare the contents of twoFiles to determine if they are equal or not.static booleancompare(java.lang.String file1, java.lang.String file2)static voidcopy(java.io.File src, java.io.File dest)Smart copy.static voidcopy(java.lang.String src, java.lang.String dest)static voidcopyDir(java.io.File srcDir, java.io.File destDir)Copies directory with specified copy params.static voidcopyDir(java.lang.String srcDir, java.lang.String destDir)static voidcopyFile(java.io.File srcFile, java.io.File destFile)Copies aFileto anotherFile.static voidcopyFile(java.lang.String srcFile, java.lang.String destFile)static java.io.FilecopyFileToDir(java.io.File srcFile, java.io.File destDir)Copies aFileto directory with specified copy params and returns copied destination.static java.io.FilecopyFileToDir(java.lang.String srcFile, java.lang.String destDir)static java.io.FilecreateTempDirectory()static java.io.FilecreateTempDirectory(java.lang.String prefix, java.lang.String suffix)static java.io.FilecreateTempDirectory(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir)Creates temporary directory.static java.io.FilecreateTempFile()static java.io.FilecreateTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir)Creates temporaryFile.static java.io.FilecreateTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir, boolean create)Creates temporaryFile.static voiddelete(java.io.File dest)Smart delete of destination file or directory.static voiddelete(java.lang.String dest)static voiddeleteDir(java.io.File destDir)Deletes a directory.static voiddeleteDir(java.lang.String destDir)static voiddeleteFile(java.io.File destFile)Deletes aFile.static voiddeleteFile(java.lang.String destFile)static booleanequals(java.io.File one, java.io.File two)Checks if twoFiles point to the sameFile.static booleanequals(java.lang.String one, java.lang.String two)static java.io.Filefile(java.lang.String fileName)Simple factory forFileobjects but with home resolving.static java.io.FilegetParentFile(java.io.File file)Returns parent for the file.static booleanisAncestor(java.io.File ancestor, java.io.File file, boolean strict)Check if oneFileis an ancestor of second one.static booleanisBinary(java.io.File file)Checks the start of the file for ASCII control charactersstatic booleanisExistingFile(java.io.File file)ReturnstrueifFileexists.static booleanisExistingFolder(java.io.File folder)Returnstrueif directory exists.static booleanisFilePathAcceptable(java.io.File file, java.io.FileFilter fileFilter)Checks if file and its ancestors are acceptable by usingFileFilter.accept(File).static booleanisNewer(java.io.File file, long timeMillis)Tests if the specifiedFileis newer than the specified time reference.static booleanisNewer(java.io.File file, java.io.File reference)UsesFile.lastModified()for reference.static booleanisNewer(java.lang.String file, long timeMillis)static booleanisNewer(java.lang.String file, java.lang.String reference)static booleanisOlder(java.io.File file, long timeMillis)Tests if the specifiedFileis older than the specified time reference.static booleanisOlder(java.io.File file, java.io.File reference)UsesFile.lastModified()for reference.static booleanisOlder(java.lang.String file, long timeMillis)static booleanisOlder(java.lang.String file, java.lang.String reference)static booleanisSymlink(java.io.File file)Deprecated.Files.isSymbolicLink(java.nio.file.Path)provides this functionality natively as of Java 1.7.static java.lang.Stringmd5(java.io.File file)Creates MD5 digest of aFile.static java.io.Filemkdir(java.io.File dir)Creates single directory.static java.io.Filemkdir(java.lang.String dir)static java.io.Filemkdirs(java.io.File dirs)Creates all directories at once.static java.io.Filemkdirs(java.lang.String dirs)static voidmove(java.io.File src, java.io.File dest)Smart move.static voidmove(java.lang.String src, java.lang.String dest)static java.io.FilemoveDir(java.io.File srcDir, java.io.File destDir)static java.io.FilemoveDir(java.lang.String srcDir, java.lang.String destDir)static java.io.FilemoveFile(java.io.File srcFile, java.io.File destFile)static java.io.FilemoveFile(java.lang.String srcFile, java.lang.String destFile)static java.io.FilemoveFileToDir(java.io.File srcFile, java.io.File destDir)Moves a file to a directory.static java.io.FilemoveFileToDir(java.lang.String srcFile, java.lang.String destDir)protected static voidoutBytes(java.io.File dest, byte[] data, int off, int len, boolean append)Writes data toFiledestination.protected static voidoutChars(java.io.File dest, char[] data, java.nio.charset.Charset encoding, boolean append)Writes characters toFiledestination.protected static voidoutString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding, boolean append)Writes data using encoding toFile.static byte[]readBytes(java.io.File file)static byte[]readBytes(java.io.File file, int count)Read file and returns byte array with contents.static byte[]readBytes(java.lang.String file)static char[]readChars(java.io.File file)static char[]readChars(java.io.File file, java.nio.charset.Charset encoding)Reads file content as char array.static char[]readChars(java.lang.String fileName)static char[]readChars(java.lang.String fileName, java.nio.charset.Charset encoding)static java.lang.String[]readLines(java.io.File source)static java.lang.String[]readLines(java.io.File file, java.nio.charset.Charset encoding)Reads lines from sourceFilewith specified encoding and returns lines asStrings in array.static java.lang.String[]readLines(java.lang.String source)static java.lang.String[]readLines(java.lang.String source, java.nio.charset.Charset encoding)static java.lang.StringreadString(java.io.File source)static java.lang.StringreadString(java.io.File file, java.nio.charset.Charset encoding)ReadsFilecontent asStringencoded in provided encoding.static java.lang.StringreadString(java.lang.String source)static java.lang.StringreadString(java.lang.String source, java.nio.charset.Charset encoding)static char[]readUTFChars(java.io.File file)Reads UTF file content as char array.static char[]readUTFChars(java.lang.String fileName)static java.lang.StringreadUTFString(java.io.File file)Detects optional BOM and reads UTFStringfrom aFile.static java.lang.StringreadUTFString(java.io.InputStream inputStream)Detects optional BOM and reads UTFStringfrom anInputStream.static java.lang.StringreadUTFString(java.lang.String fileName)static java.lang.Stringsha256(java.io.File file)Creates SHA-256 digest of a file.static java.lang.Stringsha512(java.io.File file)Creates SHA-512 digest of a file.static java.io.FiletoContainerFile(java.net.URL url)Returns a file of either a folder or a containing archive.static java.io.FiletoFile(java.net.URL url)ConvertsFileURLs toFile.static java.lang.StringtoFileName(java.net.URL url)ConvertsFileURLs to file name.static voidtouch(java.io.File file)Implements the Unix "touch" utility.static voidtouch(java.lang.String file)static java.net.URLtoURL(java.io.File file)ConvertsFiletoURLin a correct way.static voidwriteBytes(java.io.File dest, byte[] data)static voidwriteBytes(java.io.File dest, byte[] data, int off, int len)Write bytes.static voidwriteBytes(java.lang.String dest, byte[] data)static voidwriteBytes(java.lang.String dest, byte[] data, int off, int len)static voidwriteChars(java.io.File dest, char[] data)static voidwriteChars(java.io.File dest, char[] data, java.nio.charset.Charset encoding)Write characters.static voidwriteChars(java.lang.String dest, char[] data)static voidwriteChars(java.lang.String dest, char[] data, java.nio.charset.Charset encoding)static voidwriteStream(java.io.FileOutputStream out, java.io.InputStream in)WriteInputStreamin toFileOutputStream.static voidwriteStream(java.io.File dest, java.io.InputStream in)static voidwriteStream(java.lang.String dest, java.io.InputStream in)static voidwriteString(java.io.File dest, java.lang.String data)static voidwriteString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding)Writes String.static voidwriteString(java.lang.String dest, java.lang.String data)static voidwriteString(java.lang.String dest, java.lang.String data, java.nio.charset.Charset encoding)
-
-
-
Method Detail
-
file
public static java.io.File file(java.lang.String fileName)
Simple factory forFileobjects but with home resolving.
-
equals
public static boolean equals(java.lang.String one, java.lang.String two)- See Also:
equals(File, File)
-
equals
public static boolean equals(java.io.File one, java.io.File two)Checks if twoFiles point to the sameFile.- Parameters:
one-Fileone.two-Filetwo.- Returns:
trueif theFiles match.
-
toFile
public static java.io.File toFile(java.net.URL url)
ConvertsFileURLs toFile. Ignores other schemes and returnsnull.
-
toURL
public static java.net.URL toURL(java.io.File file) throws java.net.MalformedURLExceptionConvertsFiletoURLin a correct way.- Returns:
URLornullin case of error.- Throws:
java.net.MalformedURLException- ifFilecannot be converted.
-
toFileName
public static java.lang.String toFileName(java.net.URL url)
ConvertsFileURLs to file name. Accepts onlyURLs with 'file' protocol. Otherwise, for other schemes returnsnull.- Parameters:
url-URLto convert- Returns:
- file name
-
toContainerFile
public static java.io.File toContainerFile(java.net.URL url)
Returns a file of either a folder or a containing archive.
-
isExistingFile
public static boolean isExistingFile(java.io.File file)
ReturnstrueifFileexists.
-
isExistingFolder
public static boolean isExistingFolder(java.io.File folder)
Returnstrueif directory exists.
-
mkdirs
public static java.io.File mkdirs(java.lang.String dirs) throws java.io.IOException- Throws:
java.io.IOException- See Also:
mkdirs(File)
-
mkdirs
public static java.io.File mkdirs(java.io.File dirs) throws java.io.IOExceptionCreates all directories at once.- Parameters:
dirs- Directories to make.- Throws:
java.io.IOException- if cannot create directory.
-
mkdir
public static java.io.File mkdir(java.lang.String dir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
mkdir(File)
-
mkdir
public static java.io.File mkdir(java.io.File dir) throws java.io.IOExceptionCreates single directory.- Throws:
java.io.IOException- if cannot create directory.
-
touch
public static void touch(java.lang.String file) throws java.io.IOException- Throws:
java.io.IOException- See Also:
touch(File)
-
touch
public static void touch(java.io.File file) throws java.io.IOExceptionImplements the Unix "touch" utility. It creates a newFilewith size 0 or, if theFileexists already, it is opened and closed without modifying it, but updating theFiledate and time.- Throws:
java.io.IOException
-
copyFile
public static void copyFile(java.lang.String srcFile, java.lang.String destFile) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyFile(File, File)
-
copyFile
public static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOExceptionCopies aFileto anotherFile.- Parameters:
srcFile- SourceFile.destFile- DestinationFile.- Throws:
java.io.IOException- if cannot copy
-
copyFileToDir
public static java.io.File copyFileToDir(java.lang.String srcFile, java.lang.String destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyFileToDir(File, File)
-
copyFileToDir
public static java.io.File copyFileToDir(java.io.File srcFile, java.io.File destDir) throws java.io.IOExceptionCopies aFileto directory with specified copy params and returns copied destination.- Throws:
java.io.IOException
-
copyDir
public static void copyDir(java.lang.String srcDir, java.lang.String destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyDir(File, File)
-
copyDir
public static void copyDir(java.io.File srcDir, java.io.File destDir) throws java.io.IOExceptionCopies directory with specified copy params.- Throws:
java.io.IOException- See Also:
_copyDirectory(File, File)
-
moveFile
public static java.io.File moveFile(java.lang.String srcFile, java.lang.String destFile) throws java.io.IOException- Throws:
java.io.IOException- See Also:
moveFile(File, File)
-
moveFile
public static java.io.File moveFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException- Throws:
java.io.IOException- See Also:
_moveFile(File, File)
-
moveFileToDir
public static java.io.File moveFileToDir(java.lang.String srcFile, java.lang.String destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
moveFileToDir(File, File)
-
moveFileToDir
public static java.io.File moveFileToDir(java.io.File srcFile, java.io.File destDir) throws java.io.IOExceptionMoves a file to a directory.- Parameters:
srcFile- SourceFile.destDir- Destination directory.- Throws:
java.io.IOException- if there is an error during move.
-
moveDir
public static java.io.File moveDir(java.lang.String srcDir, java.lang.String destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
moveDir(File, File)
-
moveDir
public static java.io.File moveDir(java.io.File srcDir, java.io.File destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
_moveDirectory(File, File)
-
deleteFile
public static void deleteFile(java.lang.String destFile) throws java.io.IOException- Throws:
java.io.IOException- See Also:
deleteFile(File)
-
deleteFile
public static void deleteFile(java.io.File destFile) throws java.io.IOExceptionDeletes aFile.- Parameters:
destFile- Destination to delete.- Throws:
java.io.IOException- if there was an error deleting.
-
deleteDir
public static void deleteDir(java.lang.String destDir) throws java.io.IOException- Throws:
java.io.IOException- See Also:
deleteDir(File)
-
deleteDir
public static void deleteDir(java.io.File destDir) throws java.io.IOExceptionDeletes a directory.- Parameters:
destDir- Destination to delete.- Throws:
java.io.IOException- if there was an error deleting.
-
cleanDir
public static void cleanDir(java.lang.String dest) throws java.io.IOException- Throws:
java.io.IOException- See Also:
cleanDir(File)
-
cleanDir
public static void cleanDir(java.io.File destDir) throws java.io.IOExceptionCleans a directory without deleting it.- Parameters:
destDir- destination to clean.- Throws:
java.io.IOException- if something went wrong.
-
readUTFChars
public static char[] readUTFChars(java.lang.String fileName) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readUTFChars(File)
-
readUTFChars
public static char[] readUTFChars(java.io.File file) throws java.io.IOExceptionReads UTF file content as char array.- Parameters:
file-Fileto read.- Returns:
- array of characters.
- Throws:
java.io.IOException- if something went wrong.
-
readChars
public static char[] readChars(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOExceptionReads file content as char array.- Parameters:
file-Fileto read.encoding- Encoding to use.- Returns:
- array of characters.
- Throws:
java.io.IOException- if something went wrong.
-
readChars
public static char[] readChars(java.lang.String fileName) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(String, Charset)
-
readChars
public static char[] readChars(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(File, Charset)
-
readChars
public static char[] readChars(java.lang.String fileName, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(File, Charset)
-
writeChars
public static void writeChars(java.io.File dest, char[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeChars(File, char[], Charset)
-
writeChars
public static void writeChars(java.lang.String dest, char[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeChars(File, char[])
-
writeChars
public static void writeChars(java.lang.String dest, char[] data, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeChars(File, char[], Charset)
-
writeChars
public static void writeChars(java.io.File dest, char[] data, java.nio.charset.Charset encoding) throws java.io.IOExceptionWrite characters. append = false- Throws:
java.io.IOException- See Also:
outChars(File, char[], Charset, boolean)
-
outChars
protected static void outChars(java.io.File dest, char[] data, java.nio.charset.Charset encoding, boolean append) throws java.io.IOExceptionWrites characters toFiledestination.- Parameters:
dest- destinationFiledata- Data as aStringencoding- Encoding as aStringappend-trueif appending;falseifFileshould be overwritten.- Throws:
java.io.IOException- if something went wrong.
-
readUTFString
public static java.lang.String readUTFString(java.lang.String fileName) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readUTFString(File)
-
readUTFString
public static java.lang.String readUTFString(java.io.File file) throws java.io.IOExceptionDetects optional BOM and reads UTFStringfrom aFile. If BOM is missing, UTF-8 is assumed.- Parameters:
file-Fileto read.- Returns:
- String in UTF encoding.
- Throws:
java.io.IOException- if copy toInputStreamerrors.- See Also:
unicodeInputStreamOf(File),IOUtil.copy(InputStream, Charset)
-
readUTFString
public static java.lang.String readUTFString(java.io.InputStream inputStream) throws java.io.IOExceptionDetects optional BOM and reads UTFStringfrom anInputStream. If BOM is missing, UTF-8 is assumed.- Parameters:
inputStream-InputStreamto read.- Returns:
- String in UTF encoding.
- Throws:
java.io.IOException- if copy toInputStreamerrors.- See Also:
unicodeInputStreamOf(File),IOUtil.copy(InputStream, Charset)
-
readString
public static java.lang.String readString(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOExceptionReadsFilecontent asStringencoded in provided encoding. For UTF encoded files, detects optional BOM characters.- Parameters:
file-Fileto read.encoding- Encoding to use.- Returns:
- String representing
Filecontent. - Throws:
java.io.IOException- if copy toInputStreamerrors.- See Also:
streamOf(File, Charset),IOUtil.copy(InputStream, Charset)
-
readString
public static java.lang.String readString(java.lang.String source) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readString(String, Charset)
-
readString
public static java.lang.String readString(java.lang.String source, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readString(File, Charset)
-
readString
public static java.lang.String readString(java.io.File source) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readString(File, Charset)
-
writeString
public static void writeString(java.lang.String dest, java.lang.String data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeString(File, String, Charset)
-
writeString
public static void writeString(java.lang.String dest, java.lang.String data, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeString(File, String, Charset)
-
writeString
public static void writeString(java.io.File dest, java.lang.String data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeString(File, String, Charset)
-
writeString
public static void writeString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding) throws java.io.IOExceptionWrites String. append = false- Throws:
java.io.IOException- See Also:
outString(File, String, Charset, boolean)
-
appendString
public static void appendString(java.lang.String dest, java.lang.String data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendString(File, String)
-
appendString
public static void appendString(java.lang.String dest, java.lang.String data, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendString(File, String, Charset)
-
appendString
public static void appendString(java.io.File dest, java.lang.String data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendString(File, String, Charset)
-
appendString
public static void appendString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding) throws java.io.IOExceptionAppends String. append = true- Throws:
java.io.IOException- See Also:
outString(File, String, Charset, boolean)
-
outString
protected static void outString(java.io.File dest, java.lang.String data, java.nio.charset.Charset encoding, boolean append) throws java.io.IOExceptionWrites data using encoding toFile.- Parameters:
dest- destinationFiledata- Data as aStringencoding- Encoding as aStringappend-trueif appending;falseifFileshould be overwritten.- Throws:
java.io.IOException- if something went wrong.
-
writeStream
public static void writeStream(java.lang.String dest, java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeStream(File, InputStream)
-
writeStream
public static void writeStream(java.io.File dest, java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeStream(FileOutputStream, InputStream)
-
writeStream
public static void writeStream(java.io.FileOutputStream out, java.io.InputStream in) throws java.io.IOExceptionWriteInputStreamin toFileOutputStream.- Parameters:
out-FileOutputStreamto write to.in-InputStreamto read.- Throws:
java.io.IOException- if there is an issue reading/writing.
-
readLines
public static java.lang.String[] readLines(java.lang.String source) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readLines(String, Charset)
-
readLines
public static java.lang.String[] readLines(java.lang.String source, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readLines(File, Charset)
-
readLines
public static java.lang.String[] readLines(java.io.File source) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readLines(File, Charset)
-
readLines
public static java.lang.String[] readLines(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOExceptionReads lines from sourceFilewith specified encoding and returns lines asStrings in array.- Parameters:
file-Fileto read.encoding- Endoing to use.- Returns:
- array of Strings which represents lines in the
File. - Throws:
java.io.IOException- ifFiledoes not exist or is not aFileor there is an issue reading theFile.
-
readBytes
public static byte[] readBytes(java.lang.String file) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(File)
-
readBytes
public static byte[] readBytes(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(File, int)
-
readBytes
public static byte[] readBytes(java.io.File file, int count) throws java.io.IOExceptionRead file and returns byte array with contents.- Parameters:
file-Fileto readcount- number of bytes to read- Returns:
- byte array from
Filecontents. - Throws:
java.io.IOException- if not aFileorFiledoes not exist or file size is larger thanInteger.MAX_VALUE.
-
writeBytes
public static void writeBytes(java.lang.String dest, byte[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeBytes(File, byte[])
-
writeBytes
public static void writeBytes(java.io.File dest, byte[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeBytes(File, byte[], int, int)
-
writeBytes
public static void writeBytes(java.lang.String dest, byte[] data, int off, int len) throws java.io.IOException- Throws:
java.io.IOException- See Also:
writeBytes(File, byte[], int, int)
-
writeBytes
public static void writeBytes(java.io.File dest, byte[] data, int off, int len) throws java.io.IOExceptionWrite bytes. append = false- Throws:
java.io.IOException- See Also:
outBytes(File, byte[], int, int, boolean)
-
appendBytes
public static void appendBytes(java.lang.String dest, byte[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendBytes(File, byte[])
-
appendBytes
public static void appendBytes(java.lang.String dest, byte[] data, int off, int len) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendBytes(File, byte[], int, int)
-
appendBytes
public static void appendBytes(java.io.File dest, byte[] data) throws java.io.IOException- Throws:
java.io.IOException- See Also:
appendBytes(File, byte[], int, int)
-
appendBytes
public static void appendBytes(java.io.File dest, byte[] data, int off, int len) throws java.io.IOExceptionAppends bytes. append = true- Throws:
java.io.IOException- See Also:
outBytes(File, byte[], int, int, boolean)
-
outBytes
protected static void outBytes(java.io.File dest, byte[] data, int off, int len, boolean append) throws java.io.IOExceptionWrites data toFiledestination.- Parameters:
dest- destinationFiledata- Data as aStringoff- the start offset in the data.len- the number of bytes to write.append-trueif appending;falseifFileshould be overwritten.- Throws:
java.io.IOException- if something went wrong.
-
compare
public static boolean compare(java.lang.String file1, java.lang.String file2) throws java.io.IOException- Throws:
java.io.IOException
-
compare
public static boolean compare(java.io.File one, java.io.File two) throws java.io.IOExceptionCompare the contents of twoFiles to determine if they are equal or not.This method checks to see if the two
Files are different lengths or if they point to the sameFile, before resorting to byte-by-byte comparison of the contents.Code origin: Avalon
- Throws:
java.io.IOException
-
isOlder
public static boolean isOlder(java.lang.String file, java.lang.String reference)- See Also:
isOlder(File, File)
-
isNewer
public static boolean isNewer(java.lang.String file, java.lang.String reference)- See Also:
isNewer(File, File)
-
isNewer
public static boolean isNewer(java.io.File file, java.io.File reference)UsesFile.lastModified()for reference.- See Also:
isNewer(File, long)
-
isOlder
public static boolean isOlder(java.io.File file, java.io.File reference)UsesFile.lastModified()for reference.- See Also:
isOlder(File, long)
-
isNewer
public static boolean isNewer(java.io.File file, long timeMillis)Tests if the specifiedFileis newer than the specified time reference.- Parameters:
file- theFileof which the modification date must be compared.timeMillis- the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Returns:
trueif theFileexists and has been modified after the given time reference.
-
isNewer
public static boolean isNewer(java.lang.String file, long timeMillis)- See Also:
isNewer(File, long)
-
isOlder
public static boolean isOlder(java.io.File file, long timeMillis)Tests if the specifiedFileis older than the specified time reference.- Parameters:
file- theFileof which the modification date must be compared.timeMillis- the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Returns:
trueif theFileexists and has been modified after the given time reference.
-
isOlder
public static boolean isOlder(java.lang.String file, long timeMillis)- See Also:
isOlder(File, long)
-
copy
public static void copy(java.lang.String src, java.lang.String dest) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(File, File)
-
copy
public static void copy(java.io.File src, java.io.File dest) throws java.io.IOExceptionSmart copy. If source is a directory, copy it to destination. Otherwise, if destination is directory, copy source file to it. Otherwise, try to copy source file to destination file.- Parameters:
src- sourceFiledest- destinationFile- Throws:
java.io.IOException- if there is an error copying.- See Also:
copyDir(File, File),copyFileToDir(File, File),copyFile(File, File)
-
move
public static void move(java.lang.String src, java.lang.String dest) throws java.io.IOException- Throws:
java.io.IOException- See Also:
move(File, File)
-
move
public static void move(java.io.File src, java.io.File dest) throws java.io.IOExceptionSmart move. If source is a directory, move it to destination. Otherwise, if destination is directory, move sourceFileto it. Otherwise, try to move sourceFileto destinationFile.- Parameters:
src- sourceFiledest- destinationFile- Throws:
java.io.IOException- if there is an error moving.- See Also:
moveDir(File, File),moveFileToDir(File, File),moveFile(File, File)
-
delete
public static void delete(java.lang.String dest) throws java.io.IOException- Throws:
java.io.IOException- See Also:
delete(File)
-
delete
public static void delete(java.io.File dest) throws java.io.IOExceptionSmart delete of destination file or directory.- Throws:
java.io.IOException- if there is an issue deleting the file/directory.- See Also:
deleteFile(File),deleteDir(File)
-
isAncestor
public static boolean isAncestor(java.io.File ancestor, java.io.File file, boolean strict)Check if oneFileis an ancestor of second one.- Parameters:
strict- if c then this method returnstrueif ancestor andFileare equal- Returns:
trueif ancestor is parent ofFile; otherwise,false
-
getParentFile
public static java.io.File getParentFile(java.io.File file)
Returns parent for the file. The method correctly processes "." and ".." inFilenames. The name remains relative if was relative before. Returnsnullif theFilehas no parent.- Parameters:
file-File- Returns:
nullif theFilehas no parent.
-
isFilePathAcceptable
public static boolean isFilePathAcceptable(java.io.File file, java.io.FileFilter fileFilter)Checks if file and its ancestors are acceptable by usingFileFilter.accept(File).- Parameters:
file-Fileto check.fileFilter-FileFilterto use.- Returns:
- if file and its ancestors are acceptable
-
createTempDirectory
public static java.io.File createTempDirectory() throws java.io.IOException- Throws:
java.io.IOException- See Also:
createTempDirectory(String, String)
-
createTempDirectory
public static java.io.File createTempDirectory(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException- Throws:
java.io.IOException- See Also:
createTempDirectory(String, String, File)
-
createTempDirectory
public static java.io.File createTempDirectory(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir) throws java.io.IOExceptionCreates temporary directory.- Throws:
java.io.IOException- See Also:
createTempFile(String, String, File)
-
createTempFile
public static java.io.File createTempFile() throws java.io.IOException- Throws:
java.io.IOException- See Also:
createTempFile(String, String, File, boolean)
-
createTempFile
public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir, boolean create) throws java.io.IOExceptionCreates temporaryFile.- Parameters:
prefix- The prefix string to be used in generating the file's name; must be at least three characters longsuffix- The suffix string to be used in generating the file's name; may benull, in which case the suffix".tmp"will be usedtempDir- The directory in which the file is to be created, ornullif the default temporary-file directory is to be usedcreate- Ifcreateis set totrueFilewill be physically created on the file system. Otherwise, it will be created and then deleted - trick that will make tempFileexist only if they are used.- Returns:
- File
- Throws:
java.io.IOException
-
createTempFile
public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File tempDir) throws java.io.IOExceptionCreates temporaryFile. Wraps Java method and repeats creation several times if something fails.- Parameters:
prefix- The prefix string to be used in generating the file's name; must be at least three characters longsuffix- The suffix string to be used in generating the file's name; may benull, in which case the suffix".tmp"will be usedtempDir- The directory in which the file is to be created, ornullif the default temporary-file directory is to be used- Throws:
java.io.IOException
-
isSymlink
@Deprecated public static boolean isSymlink(java.io.File file)
Deprecated.Files.isSymbolicLink(java.nio.file.Path)provides this functionality natively as of Java 1.7.Determines whether the specified file is a symbolic link rather than an actual file.
-
md5
public static java.lang.String md5(java.io.File file) throws java.io.IOExceptionCreates MD5 digest of aFile.- Parameters:
file-Fileto create digest of.- Returns:
- MD5 digest of the
File. - Throws:
java.io.IOException
-
sha256
public static java.lang.String sha256(java.io.File file) throws java.io.IOExceptionCreates SHA-256 digest of a file.- Parameters:
file-Fileto create digest of.- Returns:
- SHA-256 digest of the
File. - Throws:
java.io.IOException
-
sha512
public static java.lang.String sha512(java.io.File file) throws java.io.IOExceptionCreates SHA-512 digest of a file.- Parameters:
file-Fileto create digest of.- Returns:
- SHA-512 digest of the
File. - Throws:
java.io.IOException
-
isBinary
public static boolean isBinary(java.io.File file) throws java.io.IOExceptionChecks the start of the file for ASCII control characters- Parameters:
file-File- Returns:
- true if the the start of the
Fileis ASCII control characters. - Throws:
java.io.IOException
-
-