@ComponentSpecification public interface FileUtil extends FileUtilLimited
File
handling and manipulation.
Files
that offers similar and additional features. However
this is not supported in limited environments such as e.g. GWT.FileUtilImpl
NO_FILES, PATH_SEGMENT_CURRENT, PATH_SEGMENT_PARENT, PROPERTY_TMP_DIR, PROPERTY_USER_HOME
Modifier and Type | Method and Description |
---|---|
boolean |
collectMatchingFiles(File cwd,
String path,
FileType fileType,
List<File> list)
This method adds all files matching the given
path and fileType to the list . |
void |
copyFile(File source,
File destination)
This method copies the file given by
source to the file given by destination . |
void |
copyFile(File source,
File destination,
boolean keepFlags)
This method copies the file given by
source to the file given by destination . |
void |
copyRecursive(File source,
File destination,
boolean allowOverwrite)
This method copies the file or directory given by
source into the given destination . |
void |
copyRecursive(File source,
File destination,
boolean allowOverwrite,
FileFilter filter)
This method copies the file or directory given by
source into the given destination . |
int |
deleteChildren(File directory)
|
int |
deleteRecursive(File path)
This method
deletes the given path . |
File[] |
getMatchingFiles(File cwd,
String path,
FileType fileType)
|
FileAccessPermissions |
getPermissions(File file,
FileAccessClass accessClass)
This method gets the
permissions of the given file . |
File |
getTemporaryDirectory()
This method gets the
File representing the temporary directory . |
File |
getUserHomeDirectory()
This method gets the
File representing the home directory of the
current user . |
void |
setPermissions(File file,
FileAccessPermissions permissions)
This method sets the
permissions of the given file . |
getBasename, getDirname, getExtension, normalizePath, normalizePath
File getUserHomeDirectory()
File
representing the home directory of the
current user
.File getTemporaryDirectory()
File
representing the temporary directory
.void copyFile(File source, File destination) throws RuntimeIoException
source
to the file given by destination
.source
- is the existing file to copy from.destination
- is the file to copy to. It will be created if it does NOT exist and overridden
otherwise.RuntimeIoException
- if the operation fails.void copyFile(File source, File destination, boolean keepFlags) throws RuntimeIoException
source
to the file given by destination
. source
- is the existing file to copy from.destination
- is the file to copy to. It will be created if it does NOT exist and overridden
otherwise.keepFlags
- - true
if the flags of the file should be copied as well, false
otherwise (a new file is created with default flags and only the content is copied).RuntimeIoException
- if the operation fails.FileAccessPermissions getPermissions(File file, FileAccessClass accessClass)
permissions
of the given file
. file
- is the file for which the permissions are requested.accessClass
- is the distinct class
the permission should be applied to in
the returned permissions. It may be null
to apply the permissions to all distinct classes.file
.void setPermissions(File file, FileAccessPermissions permissions)
permissions
of the given file
. FileAccessClass.OTHERS
and FileAccessClass.USER
so FileAccessClass.GROUP
flags
are ignored as well as the global s-bits (sticky
,
setgid
and setuid
).file
- is the file to modify.permissions
- are the permissions to set.void copyRecursive(File source, File destination, boolean allowOverwrite) throws RuntimeIoException
source
into the given destination
. source
a new name
, the
destination
has to point to the final place where the copy should appear rather than the
directory where the copy will be located in. File
source = newFile
("/usr/local/foo");File
destination = newFile
("/tmp", source.getName()); // file: "/tmp/foo"fileUtil
.copyRecursive
(source, destination, true);
source
- is the file or directory to copy.destination
- is the final place where the copy should appear.allowOverwrite
- - if false
and the destination
already exists, a
RuntimeIoException
is thrown, else if true
the destination
will be
overwritten.RuntimeIoException
- if the operation fails.void copyRecursive(File source, File destination, boolean allowOverwrite, FileFilter filter) throws RuntimeIoException
source
into the given destination
. source
a new name
, the
destination
has to point to the final place where the copy should appear rather than the
directory where the copy will be located in. source
- is the file or directory to copy.destination
- is the final place where the copy should appear.allowOverwrite
- - if false
and the destination
already exists, a
RuntimeIoException
is thrown, else if true
the destination
will be
overwritten.filter
- is a FileFilter
that decides
which files should be
copied. Only accepted
files and directories are copied, others
will be ignored.RuntimeIoException
- if the operation fails.copyRecursive(File, File, boolean)
int deleteRecursive(File path) throws RuntimeIoException
deletes
the given path
. If the path
denotes a
directory
then it will be deleted recursively.path
- is the path to delete.RuntimeIoException
- if a file or directory could NOT be deleted
.deleteChildren(File)
int deleteChildren(File directory) throws RuntimeIoException
deletes
all children
of the given
directory
recursively. If the given directory
denotes an existing
directory
then it will be empty after the call of this method, else this
method will have no effect.directory
- is the directory to delete.RuntimeIoException
- if a file or directory could NOT be deleted
.File[] getMatchingFiles(File cwd, String path, FileType fileType)
files
matching to the given path
and fileType
. The
path
may contain wildcards
. getMatchingFiles
(cwd,
"*", FileType.DIRECTORY
)
will return all directories
in
cwd
getMatchingFiles
(cwd,
"*/*.xml", FileType.FILE
)
will return all files
from all direct
sub-folders
of cwd
that end with ".xml"getMatchingFiles
(cwd,
"**/*.xml", FileType.FILE
)
will return all files
in cwd
or any of its transitive sub-folders
that end with ".xml"cwd
- is the current working directory and should therefore point to an existing
directory
. If the given path
is NOT absolute
it is interpreted relative to this directory.path
- is the path the requested files must match. If this path is NOT absolute
it is interpreted relative to the directory
given by
cwd
.fileType
- is the type of the requested files or null
if files of any type are acceptable.files
that match the given path
and apply to
ignore
collectMatchingFiles(File, String, FileType, List)
boolean collectMatchingFiles(File cwd, String path, FileType fileType, List<File> list)
path
and fileType
to the list
. The
path
may contain wildcards
.cwd
- is the current working directory and should therefore point to an existing
directory
. If the given path
is NOT absolute
it is interpreted relative to this directory.path
- is the path the files to collect must match. If this path is NOT absolute
it is interpreted relative to the directory
given by
cwd
.fileType
- is the type of the files to collect or null
if files of any type are acceptable.list
- is the list where to add
the collected files.false
if the path is a regular string and true
if the given path contains at
least one wildcard
( '*'
or
'?'
).Copyright © 2001–2016 mmm-Team. All rights reserved.