| Modifier and Type | Class and Description |
|---|---|
static class |
FileTools.Lock |
| Modifier and Type | Field and Description |
|---|---|
static String |
DIRECTORY_LOCK |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendFile(File source,
File destination)
Concatenate the two files given in
source and
destination. |
static File |
checkDirectory(File dir,
boolean create,
boolean checkCanRead,
boolean checkCanWrite)
Utility method for checking the availablity of a directory.
|
static File |
checkDirectory(String path,
boolean create,
boolean checkCanRead,
boolean checkCanWrite) |
static void |
copyBinaryFile(File source,
File destination)
Copy the byte content of
source to destination. |
static void |
copyFile(File source,
File destination) |
static void |
copyFile(File source,
String sourceEncoding,
File destination,
String destinationEncoding)
Copy the character content of
source to
destination. |
static void |
copyRecursively(File source,
File destination) |
static File |
copyRecursivelyInto(File source,
File destinationParent,
String newName) |
static void |
createEmptyFile(File file)
Create an empty file.
|
static File |
createTempFile(File file)
Create a file object representing a temporary file in the user's temp dir
with the same name as the given file.
|
static File |
createTempFile(String filename)
Create a file object representing a temporary file in the user's temp dir
with the given filename.
|
static void |
delete(File master)
The delete operation that Java should have provided....
|
static void |
deleteAfter(File directory,
long millis,
boolean recursiveScan)
Delete any file in
directory that is older than
millis milliseconds. |
static void |
deleteEmptyDirectories(File root,
File file)
Delete all empty directories in the parent hierarchy of file, up to and
excluding root.
|
static boolean |
deleteRecursivly(File file)
Deletes a file or directory, if necessary recursivly.
|
static boolean |
deleteRecursivly(File file,
boolean deleteRoot)
Deletes a file or directory, if necessary recursivly.
|
static boolean |
equalsOnSystem(File source,
File destination)
true when the two files represent the same physical file in
the file system. |
static String |
getBaseName(File file)
Get the local name of the file in its directory without the extension.
|
static String |
getBaseName(String filename)
Get the local name of the file in its directory without the extension.
|
static String |
getBaseName(String filename,
String extensionPrefix,
String defaultName)
Get the local name of the file in its directory without the extension.
|
static String |
getEncoding() |
static String |
getExtension(File file)
Get the extension of the file name.
|
static String |
getExtension(String filename)
Get the extension of the file name.
|
static String |
getExtension(String filename,
String extensionPrefix,
String defaultName)
Get the extension of the file name.
|
static String |
getFileName(File file) |
static String |
getFileName(String filename)
Get the local name of the file in its directory (with extension).
|
static String |
getFileName(String filename,
String defaultName)
Get the local name of the file in its directory (with extension).
|
static File |
getParentFile(File file)
Try to get a valid parent for file.
|
static String |
getPathName(File file) |
static String |
getPathName(String filename)
Get the path name of the file.
|
static String |
getPathName(String filename,
String defaultName)
Get the path part of the file name.
|
static String |
getPathRelativeTo(File file,
File base)
get relative path of "file" with respect to "base" directory example :
base = /a/b/c;
file = /a/d/e/x.txt;
getRelativePath(file, base) == ../.. |
static String |
getPathRelativeTo(File file,
File base,
boolean ifAncestor) |
static boolean |
hasLeadingSeparator(String path) |
static boolean |
hasTrailingSeparator(String path) |
static boolean |
isAncestor(File parent,
File descendant) |
static boolean |
isExtensionMatch(File file,
String extensions) |
static boolean |
isLegalPath(String filename) |
static boolean |
isLocked(File file)
Answer true if a cooperative
FileTools.Lock is held on file. |
static boolean |
isReadOnly(File file) |
static boolean |
isWindows() |
static String |
joinPath(String... segment)
Join all segments to a valid file path.
|
static FileTools.Lock |
lock(File file)
Create a cooperative
FileTools.Lock for file. |
static void |
renameFile(File source,
File destination) |
static void |
renameFile(File source,
String sourceEncoding,
File destination,
String destinationEncoding)
"Rename" a file.
|
static File |
resolvePath(File parent,
String path)
Return a new
File instance for "path". |
static byte[] |
toBytes(File file)
Create a byte array with the files content.
|
static String |
toString(File file)
Read a file's content at once and return as a string.
|
static String |
toString(File file,
String encoding)
Read a file's content at once and return as a string in the correct
encoding.
|
static String |
trimPath(String param)
Replaces all characters that are generally not allowed or considered
useful in filenames with underscore.
|
static void |
wait(File file,
long timeout,
long delay)
Wait for a file to arrive.
|
static String |
withoutTrailingSeparator(String path)
Ensure path has no trailing file separator char.
|
static String |
withTrailingSeparator(String path)
Ensure path has a trailing file separator char.
|
static void |
write(File file,
byte[] bytes)
Create a file from the byte content.
|
static void |
write(File file,
String text)
Create a file from the string content.
|
static void |
write(File file,
String text,
boolean append)
Create a file from the string content.
|
static void |
write(File file,
String text,
String encoding)
Create a file from the string content.
|
static void |
write(File file,
String text,
String encoding,
boolean append)
Create a file from the string content / append a string to a file
|
public static final String DIRECTORY_LOCK
public static void appendFile(File source, File destination) throws IOException
source and
destination.source - The file to be appended.destination - The file to append to.IOExceptionpublic static File checkDirectory(File dir, boolean create, boolean checkCanRead, boolean checkCanWrite) throws IOException
dir - The directory to check.create - Flag if we should create if dir not already exists.checkCanRead - Flag if we should check read permission.checkCanWrite - Flag if we should check write permission.IOExceptionpublic static File checkDirectory(String path, boolean create, boolean checkCanRead, boolean checkCanWrite) throws IOException
IOExceptioncheckDirectory(File, boolean, boolean, boolean)public static void copyBinaryFile(File source, File destination) throws IOException
source to destination.source - The file whose contents we should copy.destination - The file where the contents are copied to.IOExceptionpublic static void copyFile(File source, File destination) throws IOException
IOExceptioncopyBinaryFile(File, File)public static void copyFile(File source, String sourceEncoding, File destination, String destinationEncoding) throws IOException
source to
destination.source - The file whose contents we should copy.sourceEncoding - The encoding of the source byte stream.destination - The file where the contents are copied to.destinationEncoding - The encoding of the destination byte stream.IOExceptionpublic static void copyRecursively(File source, File destination) throws IOException
IOExceptionpublic static File copyRecursivelyInto(File source, File destinationParent, String newName) throws IOException
IOExceptionpublic static void createEmptyFile(File file) throws IOException
file - IOExceptionpublic static File createTempFile(File file) throws IOException
file - file to useIOExceptionpublic static File createTempFile(String filename) throws IOException
This does not actually create a file in the file system.
filename - filename to useIOExceptionpublic static void delete(File master) throws IOException
IOException is thrown.master - IOExceptionpublic static void deleteAfter(File directory, long millis, boolean recursiveScan) throws IOException
directory that is older than
millis milliseconds. When recursiveScan is
true the directory lookup is made recursive.directory - The directory to scan.millis - The number of milliseconds a file is allowed to live.recursiveScan - Flag if we should handle directories recursive.IOExceptionpublic static void deleteEmptyDirectories(File root, File file)
root - file - public static boolean deleteRecursivly(File file)
Returns true if file could be deleted inclusive its
components, otherwise false.
file - The file or directory to delete.true if file could be deleted inclusive its
components, otherwise false.public static boolean deleteRecursivly(File file, boolean deleteRoot)
Returns true if file could be deleted inclusive its
components, otherwise false.
file - The file or directory to delete.deleteRoot - Flag if the root directory should be deleted itself.true if file could be deleted inclusive its
components, otherwise false.public static boolean equalsOnSystem(File source, File destination)
true when the two files represent the same physical file in
the file system.source - The first file to be checked.destination - The second file to be checked.true when the two files represent the same physical
file in the file system.public static String getBaseName(File file)
file - The file whose base name is requested.public static String getBaseName(String filename)
filename - The filename whose base name is requested.public static String getBaseName(String filename, String extensionPrefix, String defaultName)
filename - The filename whose base name is requested.extensionPrefix - An optional static prefix that should be considered part of
the extension, not the basename.defaultName - returned if filename is null or a empty Stringpublic static String getEncoding()
public static String getExtension(File file)
file - The file whose extension is requested.public static String getExtension(String filename)
filename - The filename whose extension is requested.public static String getExtension(String filename, String extensionPrefix, String defaultName)
filename - The filename whose extension is requested.extensionPrefix - An extension may use a prefix (by some unique timestamp e.g.)
like defaultName - returned if the filename is empty or null or there is no
extensionpublic static String getFileName(String filename)
filename - The filename whose name is requested.public static String getFileName(String filename, String defaultName)
filename - The filename whose name is requested.defaultName - returned if filename is null or a empty Stringpublic static File getParentFile(File file)
file - public static String getPathName(File file)
filename - The filename whose path is requested.defaultName - returned if filename is null or a empty Stringpublic static String getPathName(String filename)
filename - The filename whose path is requested.defaultName - returned if filename is null or a empty Stringpublic static String getPathName(String filename, String defaultName)
"gnu.txt" -> ""
"/gnu.txt" -> "/"
"a/gnu.txt" -> "a"
"/a/gnu.txt" -> "/a"
filename - The filename whose path is requested.defaultName - returned if filename is null or a empty Stringpublic static String getPathRelativeTo(File file, File base) throws IOException
base = /a/b/c;
file = /a/d/e/x.txt;
getRelativePath(file, base) == ../../d/e/x.txt;
base - base path, should be a directory, not a file, or it doesn't
make sensefile - file to generate path forIOExceptionpublic static boolean hasLeadingSeparator(String path)
public static boolean hasTrailingSeparator(String path)
public static boolean isLegalPath(String filename)
public static boolean isLocked(File file)
FileTools.Lock is held on file.file - public static boolean isReadOnly(File file)
public static boolean isWindows()
public static String joinPath(String... segment)
segment - Array of path segmentspublic static FileTools.Lock lock(File file)
FileTools.Lock for file.
This is not appropriate for synchronization with partners that are not
aware of this special protocol as no real synchronization is done on the
target file. The cooperating system must agree on this special protocol
implemented here.
The lock is implemented using an explicit standin file. For a file this
is "file - public static void renameFile(File source, File destination) throws IOException
IOExceptionrenameFile(File, String, File, String)public static void renameFile(File source, String sourceEncoding, File destination, String destinationEncoding) throws IOException
The effect is that there is a new file destination, encoded
in destinationEncoding, the old file source is
deleted.
source - The source name of the file.sourceEncoding - The encoding of the source file.destination - The destination name of the file.destinationEncoding - The encoding of the destination file.IOExceptionpublic static File resolvePath(File parent, String path)
File instance for "path". If path is relative, than
it will be interpreted as a child of "parent", if it is absolute, it is
returned as is.
ATTENTION: On windows, if "path" is absolute but without drive or UNC prefix, this root information is NOT taken from "parent".
parent - path - File instance for "path".public static byte[] toBytes(File file) throws IOException
file - The file to read.IOExceptionpublic static String toString(File file) throws IOException
Use with care!
file - The file to read.IOExceptionpublic static String toString(File file, String encoding) throws IOException
Use with care!
file - The file to read.encoding - The encoding to use.IOExceptionpublic static String trimPath(String param)
param - java.lang.Stringpublic static void wait(File file, long timeout, long delay) throws IOException
The method waits at most timeout milliseconds for a file to
arrive. When delay is != 0 the method checks the file's size
for changes until it reaches a stable size.
file - The file to wait for.timeout - The maximum time in milliseconds to wait for first occurence
of file.delay - The number of milliseconds between two checks against the
files size.IOExceptionpublic static String withoutTrailingSeparator(String path)
path - public static String withTrailingSeparator(String path)
path - public static void write(File file, byte[] bytes) throws IOException
file - The file to write/createbytes - The data to be written into the file.IOExceptionpublic static void write(File file, String text) throws IOException
file - The file to write/createtext - The text to be written into the file.IOExceptionpublic static void write(File file, String text, boolean append) throws IOException
file - The file to write/createtext - The text to be written into the file.append - Flag to append to an existing file or create a new file.IOExceptionpublic static void write(File file, String text, String encoding) throws IOException
file - The file to write/createtext - The text to be written into the file.IOExceptionpublic static void write(File file, String text, String encoding, boolean append) throws IOException
file - The file to write/createtext - The text to be written into the file.append - Flag to append to an existing file or create a new file.IOExceptionCopyright © 2013 intarsys consulting GmbH. All Rights Reserved.