@Immutable public final class FileUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canExecute(File aFile)
Tests whether the application can execute the file denoted by this abstract
pathname.
|
static boolean |
canRead(File aFile)
Tests whether the application can read the file denoted by this abstract
pathname.
|
static boolean |
canReadAndWriteFile(File aFile)
Check if the passed file can read and write.
|
static boolean |
canWrite(File aFile)
Tests whether the application can modify the file denoted by this abstract
pathname.
|
static EChange |
ensureParentDirectoryIsPresent(File aFile) |
static boolean |
existsDir(File aDir)
Check if the passed directory exists.
|
static boolean |
existsFile(File aFile)
Check if the passed file exists.
|
static File |
getCanonicalFile(File aFile) |
static List<File> |
getDirectoryContent(File aDirectory)
This is a replacement for
File.listFiles() doing some
additional checks on permissions. |
static List<File> |
getDirectoryContent(File aDirectory,
FileFilter aFileFilter)
This is a replacement for
File.listFiles(FileFilter) doing
some additional checks on permissions. |
static List<File> |
getDirectoryContent(File aDirectory,
FilenameFilter aFilenameFilter)
This is a replacement for
File.listFiles(FilenameFilter) doing
some additional checks on permissions. |
static int |
getDirectoryObjectCount(File aDirectory)
Returns the number of files and directories contained in the passed
directory excluding the system internal directories.
|
static FileChannel |
getFileReadChannel(File aFile) |
static FileChannel |
getFileReadChannel(String sFilename) |
static long |
getFileSize(FileChannel aChannel) |
static String |
getFileSizeDisplay(File aFile) |
static String |
getFileSizeDisplay(File aFile,
int nDecimals) |
static String |
getFileSizeDisplay(long nFileSize) |
static String |
getFileSizeDisplay(long nFileSize,
int nDecimals) |
static FileChannel |
getFileWriteChannel(File aFile) |
static FileChannel |
getFileWriteChannel(File aFile,
EAppend eAppend) |
static FileChannel |
getFileWriteChannel(String sFilename) |
static FileChannel |
getFileWriteChannel(String sFilename,
EAppend eAppend) |
static InputStream |
getInputStream(File aFile) |
static InputStream |
getInputStream(String sFilename) |
static InputStream |
getMappedInputStream(File aFile)
Get an input stream to the specified file, using memory mapping.
|
static OutputStream |
getMappedOutputStream(File aFile) |
static OutputStream |
getMappedOutputStream(File aFile,
EAppend eAppend) |
static OutputStream |
getMappedOutputStream(String sFilename) |
static OutputStream |
getMappedOutputStream(String sFilename,
EAppend eAppend) |
static OutputStream |
getOutputStream(File aFile)
Get an output stream for writing to a file.
|
static OutputStream |
getOutputStream(File aFile,
EAppend eAppend)
Get an output stream for writing to a file.
|
static OutputStream |
getOutputStream(String sFilename)
Get an output stream for writing to a file.
|
static OutputStream |
getOutputStream(String sFilename,
EAppend eAppend)
Get an output stream for writing to a file.
|
static RandomAccessFile |
getRandomAccessFile(File aFile,
ERandomAccessFileMode eMode) |
static RandomAccessFile |
getRandomAccessFile(String sFilename,
ERandomAccessFileMode eMode) |
static File |
getSecureFile(File aFile)
Get a secure
File object based on the passed file object. |
static boolean |
isFileNewer(File aFile1,
File aFile2)
Returns
true if the first file is newer than the second file. |
static boolean |
isParentDirectory(File aSearchDirectory,
File aStartDirectory)
Check if the searched directory is a parent object of the start directory
|
public static boolean existsFile(@Nonnull File aFile)
aFile - The file to be checked for existence. May not be null .true if the File is a file and exists,
false otherwise.public static boolean existsDir(@Nonnull File aDir)
aDir - The directory to be checked for existence. May not be
null.true if the File is a directory and exists,
false otherwise.public static boolean canRead(@Nonnull File aFile)
aFile - The file to be checked. May not be null.true if and only if the file specified by this
abstract pathname exists and can be read by the
application; false otherwisepublic static boolean canWrite(@Nonnull File aFile)
aFile - The file to be checked. May not be null.true if and only if the file system actually contains
a file denoted by this abstract pathname and the
application is allowed to write to the file; false
otherwise.public static boolean canExecute(@Nonnull File aFile)
aFile - The file to be checked. May not be null.true if and only if the abstract pathname exists
and the application is allowed to execute the filepublic static boolean canReadAndWriteFile(@Nonnull File aFile)
aFile - The file to be checked. May not be null.true if the file can be read or write@Nonnull public static EChange ensureParentDirectoryIsPresent(@Nonnull File aFile)
@Nullable public static File getCanonicalFile(@Nullable File aFile) throws IOException
IOExceptionpublic static boolean isParentDirectory(@Nonnull File aSearchDirectory, @Nonnull File aStartDirectory)
aSearchDirectory - The directory to be searched. May not be null.aStartDirectory - The directory where the search starts. May not be null.true if the search directory is a parent of the start
directory, false otherwise.@CheckForSigned public static long getFileSize(@Nonnull@WillNotClose FileChannel aChannel)
@Nullable public static FileChannel getFileReadChannel(@Nonnull String sFilename)
@Nullable public static FileChannel getFileReadChannel(@Nonnull File aFile)
@Nullable public static InputStream getInputStream(@Nonnull String sFilename)
@Nullable public static InputStream getInputStream(@Nonnull File aFile)
@Nullable public static InputStream getMappedInputStream(@Nonnull File aFile)
FileInputStream is returned.aFile - The file to use. May not be null.@Nullable public static FileChannel getFileWriteChannel(@Nonnull String sFilename)
@Nullable public static FileChannel getFileWriteChannel(@Nonnull String sFilename, @Nonnull EAppend eAppend)
@Nullable public static FileChannel getFileWriteChannel(@Nonnull File aFile)
@Nullable public static FileChannel getFileWriteChannel(@Nonnull File aFile, @Nonnull EAppend eAppend)
@Nullable public static OutputStream getOutputStream(@Nonnull String sFilename)
sFilename - The name of the file to write to. May not be null.null if the file could not be opened@Nullable public static OutputStream getOutputStream(@Nonnull String sFilename, @Nonnull EAppend eAppend)
sFilename - The name of the file to write to. May not be null.eAppend - Appending mode. May not be null.null if the file could not be opened@Nullable public static OutputStream getOutputStream(@Nonnull File aFile)
aFile - The file to write to. May not be null.null if the file could not be opened@Nullable public static OutputStream getOutputStream(@Nonnull File aFile, @Nonnull EAppend eAppend)
aFile - The file to write to. May not be null.eAppend - Appending mode. May not be null.null if the file could not be opened@Nullable public static OutputStream getMappedOutputStream(@Nonnull String sFilename)
@Nullable public static OutputStream getMappedOutputStream(@Nonnull String sFilename, @Nonnull EAppend eAppend)
@Nullable public static OutputStream getMappedOutputStream(@Nonnull File aFile)
@Nullable public static OutputStream getMappedOutputStream(@Nonnull File aFile, @Nonnull EAppend eAppend)
@Nullable public static RandomAccessFile getRandomAccessFile(@Nonnull String sFilename, @Nonnull ERandomAccessFileMode eMode)
@Nullable public static RandomAccessFile getRandomAccessFile(@Nonnull File aFile, @Nonnull ERandomAccessFileMode eMode)
public static boolean isFileNewer(@Nonnull File aFile1, @Nonnull File aFile2)
true if the first file is newer than the second file.
Returns true if the first file exists and the second file does
not exist. Returns false if the first file is older than the
second file. Returns false if the first file does not exists
but the second does. Returns false if none of the files exist.aFile1 - First file. May not be null.aFile2 - Second file. May not be null.true if the first file is newer than the second file,
false otherwise.@Nonnull public static String getFileSizeDisplay(@Nullable File aFile, @Nonnegative int nDecimals)
@Nonnull public static String getFileSizeDisplay(@Nonnegative long nFileSize, @Nonnegative int nDecimals)
@Nullable public static File getSecureFile(@Nullable File aFile)
File object based on the passed file object. First all
relative paths ("." and "..") are resolved and all eventually contained
'\0' characters are eliminated. Than all file names are checked for
validity (so that no special characters are contained).aFile - The file to be secured.null if the passed file is null.@Nonnegative public static int getDirectoryObjectCount(@Nonnull File aDirectory)
aDirectory - The directory to check. May not be null and must be a
directory.FilenameHelper.isSystemInternalDirectory(CharSequence)@Nonnull @ReturnsMutableCopy public static List<File> getDirectoryContent(@Nonnull File aDirectory)
File.listFiles() doing some
additional checks on permissions. The order of the returned files is
defined by the underlying File.listFiles() method.aDirectory - The directory to be listed. May not be null.null.@Nonnull @ReturnsMutableCopy public static List<File> getDirectoryContent(@Nonnull File aDirectory, @Nonnull FilenameFilter aFilenameFilter)
File.listFiles(FilenameFilter) doing
some additional checks on permissions. The order of the returned files is
defined by the underlying File.listFiles(FilenameFilter) method.aDirectory - The directory to be listed. May not be null.aFilenameFilter - The filename filter to be used. May not be null.null.@Nonnull @ReturnsMutableCopy public static List<File> getDirectoryContent(@Nonnull File aDirectory, @Nonnull FileFilter aFileFilter)
File.listFiles(FileFilter) doing
some additional checks on permissions. The order of the returned files is
defined by the underlying File.listFiles(FileFilter) method.aDirectory - The directory to be listed. May not be null.aFileFilter - The file filter to be used. May not be null.null.Copyright © 2006–2015 phloc systems. All rights reserved.