Add utility methods to standard classes File and Path
| Type | Name and description |
|---|---|
java.lang.String |
permissions |
java.lang.String |
permissions |
java.lang.String |
permissions |
java.lang.String |
permissions |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static boolean |
canExecute(java.nio.file.Path self)Tests whether the application can execute the file denoted by this abstract pathname. |
|
static boolean |
canRead(java.nio.file.Path self)Tests whether the application can read the file denoted by this abstract pathname. |
|
static boolean |
canWrite(java.nio.file.Path self)Tests whether the application can modify the file denoted by this abstract pathname. |
|
static void |
closeQuietly(java.io.Closeable self)Close a file in safe manner i.e. without throwing eventual exception raised by the *close* operation |
|
static java.nio.file.Path |
complete(java.nio.file.Path self)A shortcut for java.nio.file.Path#toAbsolutePath() and java.nio.file.Path#normalize() |
|
static java.io.File |
copyTo(java.io.File source, java.io.File target)Copy or a file or a directory content. |
|
static java.nio.file.Path |
copyTo(java.nio.file.Path source, java.nio.file.Path target)Copy a file or a directory content. |
|
static java.io.File |
copyTo(java.io.File source, java.lang.String target)Copy or a file or a directory content. |
|
static java.nio.file.Path |
copyTo(java.nio.file.Path source, java.lang.String target)Copy or a file or a directory content. |
|
static void |
createDirIfNotExists(java.nio.file.Path target)Create a folder if not already exists |
|
static void |
createDirIfNotExists(java.io.File target) |
|
static boolean |
delete(java.nio.file.Path path)Deletes the file or directory denoted by this abstract pathname. |
|
static boolean |
deleteDir(java.nio.file.Path path)Deletes a directory with all contained files and subdirectories. |
|
static void |
deleteOnExit(java.nio.file.Path self) |
|
static java.nio.file.Path |
div(java.nio.file.Path path, java.lang.String other) |
|
static java.nio.file.Path |
div(java.nio.file.Path path, java.nio.file.Path other) |
|
static boolean |
empty(java.io.File file)Check if a file - or - a directory is empty |
|
static boolean |
empty(java.nio.file.Path path)Check if a file - or - a directory is empty |
|
static boolean |
exists(java.nio.file.Path self, java.nio.file.LinkOption... options) |
|
static java.lang.String |
getBaseName(java.io.File file, int times = 1 )Gets the base name, minus the full path and extension, from a full filename. |
|
static java.lang.String |
getBaseName(java.nio.file.Path self, int times = 1 )Gets the base name, minus the full path and extension, from a full filename. |
|
static java.lang.String |
getExtension(java.io.File file)Gets the extension of a filename. |
|
static java.lang.String |
getExtension(java.nio.file.Path file)Retrieve the file name extension |
|
static java.lang.String |
getName(java.nio.file.Path self)Extend Path adding a getName method semantically equivalent to File#getName |
|
static java.lang.String |
getPermissions(java.nio.file.Path self)Get the file Unix permission as a string e.g. |
|
static java.lang.String |
getScheme(java.nio.file.Path path) |
|
static java.lang.String |
getSimpleName(java.io.File self)Extend File adding a getSimpleName() method which returns the
file base name removing all file extension. |
|
static java.lang.String |
getSimpleName(java.nio.file.Path self)Extend Path adding a getSimpleName() method which returns the
file base name removing all file extension. |
|
static java.net.URI |
getUri(java.nio.file.Path self) |
|
static java.net.URI |
getUri(java.io.File self) |
|
static java.lang.CharSequence |
head(java.io.Reader reader, int n)Read 'n' lines from the beginning of a Reader object. |
|
static java.lang.CharSequence |
head(java.io.InputStream stream, int n, java.lang.Object charset)Read 'n' lines from the beginning of a InputStream object. |
|
static java.lang.CharSequence |
head(java.io.File file, int n, java.lang.Object charset = null )Read the top from the beginning of a File object, stopping as soon as
'n' lines has been read. |
|
static java.lang.CharSequence |
head(java.nio.file.Path path, int n, java.lang.Object charset = null )Read the top from the beginning of a Path object, stopping as soon as
'n' lines has been read. |
|
static boolean |
isDirectory(java.nio.file.Path self, java.nio.file.LinkOption... options) |
|
static boolean |
isFile(java.nio.file.Path self, java.nio.file.LinkOption... options) |
|
static boolean |
isHidden(java.nio.file.Path self) |
|
static boolean |
isLink(java.nio.file.Path self) |
|
static long |
lastModified(java.nio.file.Path self, java.nio.file.LinkOption... options)Returns the time that the file denoted by this abstract pathname was last modified. |
|
static java.lang.String[] |
list(java.nio.file.Path self)List the content of a given path folder. |
|
static java.nio.file.Path[] |
listFiles(java.nio.file.Path self, groovy.lang.Closure<java.lang.Boolean> filter = null)List the content of a given path folder. |
|
static boolean |
matches(java.nio.file.Path self, java.lang.String pattern) |
|
static boolean |
matches(java.io.File self, java.lang.String pattern) |
|
static java.nio.file.Path |
minus(java.nio.file.Path path, int i) |
|
static boolean |
mkdir(java.nio.file.Path self, java.nio.file.attribute.FileAttribute<?>... attr)Creates the directory named by this abstract pathname |
|
static boolean |
mkdirs(java.nio.file.Path self, java.nio.file.attribute.FileAttribute<?>... attr)Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.util.Map opts, java.nio.file.Path link)Make a symbolic or a hard file system link |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.util.Map opts, java.io.File link) |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.util.Map opts, java.lang.String link) |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.nio.file.Path link) |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.io.File link) |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.lang.String link) |
|
static java.nio.file.Path |
mklink(java.nio.file.Path existing, java.util.Map opts = null ) |
|
static java.io.File |
moveTo(java.io.File source, java.io.File target)Move a file or a directory. |
|
static java.io.File |
moveTo(java.io.File source, java.lang.String target)Move a file or a directory. |
|
static java.nio.file.Path |
moveTo(java.nio.file.Path source, java.nio.file.Path target)Move a file or a directory. |
|
static java.nio.file.Path |
moveTo(java.nio.file.Path source, java.lang.String target) |
|
static java.nio.file.Path |
or(java.nio.file.Path path, java.lang.String other) |
|
static java.nio.file.Path |
or(java.nio.file.Path path, java.nio.file.Path other) |
|
static java.nio.file.Path |
plus(java.nio.file.Path path, java.lang.String other) |
|
static java.nio.file.Path |
plus(java.nio.file.Path path, java.nio.file.Path other) |
|
static java.nio.file.attribute.BasicFileAttributes |
readAttributes(java.nio.file.Path path) |
|
static boolean |
renameTo(java.nio.file.Path self, java.nio.file.Path target) |
|
static boolean |
renameTo(java.nio.file.Path self, java.lang.String target) |
|
static java.nio.file.Path |
resolveSymLink(java.nio.file.Path self)Resolve a symbolic link to the actual target file, in a similar manner to the Linux readlink -f command. |
|
static java.io.File |
resolveSymLink(java.io.File self) |
|
static void |
rollFile(java.nio.file.Path self, int maxRolls = 9 )Roll a file moving to a new path whose name ends with .1 |
|
static boolean |
setExecutable(java.nio.file.Path self, boolean executable, boolean ownerOnly = true)Sets the owner's or everybody's execute permission for the specified file. |
|
static boolean |
setLastModified(java.nio.file.Path self, long time)Sets the last-modified time of the file or directory named by this Path. |
|
static boolean |
setPermissions(java.nio.file.Path self, java.lang.String permissions)Set the file Unix permissions using a string like rw-r--r-- |
|
static boolean |
setPermissions(java.io.File self, java.lang.String permissions)Set the file Unix permissions using a string like rw-r--r-- |
|
static boolean |
setPermissions(java.nio.file.Path self, int owner, int group, int other)Set the file Unix permission using the digit representing the respectively the permissions for the owner, the group and others. |
|
static boolean |
setPermissions(java.io.File self, int owner, int group, int other)Set the file Unix permission using the digit representing the respectively the permissions for the owner, the group and others. |
|
static boolean |
setReadOnly(java.nio.file.Path self)Marks the file or directory named by this abstract pathname so that only read operations are allowed. |
|
static boolean |
setReadable(java.nio.file.Path self, boolean readable, boolean ownerOnly = true)A convenience method to set the owner's read permission for the specified file |
|
static boolean |
setWritable(java.nio.file.Path self, boolean writable, boolean ownerOnly = true )Sets the owner's or everybody's write permission for the specified file. |
|
static java.lang.CharSequence |
tail(java.nio.channels.SeekableByteChannel channel, int n, java.lang.Object charset = null, int blockSize = DEFAULT_TAIL_BLOCK_SIZE )Read the last 'n' lines from a SeekableByteChannel without reading the previous content. |
|
static java.lang.CharSequence |
tail(java.nio.file.Path path, int n, java.lang.Object charset = null, int blockSize = DEFAULT_TAIL_BLOCK_SIZE)Read the last 'n' lines from a Path without reading all the file content |
|
static java.lang.CharSequence |
tail(java.io.Reader reader, int n)Read the last 'n' lines from a Path without reading all the file content |
|
static java.lang.CharSequence |
tail(java.io.InputStream stream, int n, java.lang.Object charset) |
|
static java.lang.CharSequence |
tail(java.io.File file, int n, java.lang.Object charset = null, int blockSize = DEFAULT_TAIL_BLOCK_SIZE )Read the last 'n' lines from a File without reading all the file content |
|
static java.lang.String |
toUriString(java.nio.file.Path path) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Tests whether the application can execute the file denoted by this abstract pathname.
java.lang.SecurityManager#checkExec(java.lang.String)
method denies execute access to the filetrue if and only if the abstract pathname exists
and the application is allowed to execute the fileTests whether the application can read the file denoted by this abstract pathname.
true if and only if the file specified by this
abstract pathname exists and can be read by the
application; false otherwiseTests whether the application can modify the file denoted by this abstract pathname.
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.Close a file in safe manner i.e. without throwing eventual exception raised by the *close* operation
self - A Closable objectA shortcut for java.nio.file.Path#toAbsolutePath() and java.nio.file.Path#normalize()
Copy or a file or a directory content.
It mimics the semantic of Linux cp -r <source> <target> command.
source - The source file or directorytarget - The target file or directory Copy a file or a directory content.
It mimics the semantic of Linux cp -r <source> <target> command.
source - The source file or directorytarget - The target file or directory Copy or a file or a directory content.
It mimics the semantic of Linux cp -r <source> <target> command.
source - The source file or directorytarget - The target file or directory Copy or a file or a directory content.
It mimics the semantic of Linux cp -r <source> <target> command.
source - The source file or directorytarget - The target file or directoryCreate a folder if not already exists
target - The folder to be createdDeletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.
Deletes a directory with all contained files and subdirectories.
The method returns
Check if a file - or - a directory is empty
file - The file under testtrue if the file does not exist or it is emptyCheck if a file - or - a directory is empty
file - The file under testtrue if the file does not exist or it is emptyGets the base name, minus the full path and extension, from a full filename. This method will handle a file in either Unix or Windows format. The text after the last forward or backslash and before the last dot is returned.
a/b/c.txt --> c a.txt --> a a/b/c --> cThe output will be the same irrespective of the machine that the code is running on.
file - The filename to query, null returns nulltimes - The number of times it checks for the extension to be removed (useful for files with multiple extensions)Gets the base name, minus the full path and extension, from a full filename. This method will handle a file in either Unix or Windows format. The text after the last forward or backslash and before the last dot is returned.
a/b/c.txt --> c a.txt --> a a/b/c --> cThe output will be the same irrespective of the machine that the code is running on.
file - The filename to query, null returns nulltimes - The number of times it checks for the extension to be removed (useful for files with multiple extensions)Gets the extension of a filename. This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.
foo.txt --> "txt" a/b/c.jpg --> "jpg" a/b.txt/c --> "" a/b/c --> ""The output will be the same irrespective of the machine that the code is running on.
file - The file to retrieve the extension of.Retrieve the file name extension
file - A Path referencing a file Extend Path adding a getName method semantically equivalent to File#getName
Get the file Unix permission as a string e.g. rw-r--r--
self - The Path for which the permissions stringrw-r--r-- Extend File adding a getSimpleName() method which returns the
file base name removing all file extension.
When a file start starts with a dot character it returns the first name token
after the dot.
For example:
a.txt --> a a.tar.gz --> a a/b/c --> c a/b/c.txt --> c / --> null
self - The file File Extend Path adding a getSimpleName() method which returns the
file base name removing all file extension.
When a file start starts with a dot character it returns the first name token
after the dot.
For example:
a.txt --> a a.tar.gz --> a a/b/c --> c a/b/c.txt --> c / --> null
self - The file Path Read 'n' lines from the beginning of a Reader object.
The method does not close the reader object, thus the caller has to call the close method on it.
reader - The source object from where read the first 'n' linesn - The number of lines to readCharSequence object Read 'n' lines from the beginning of a InputStream object.
The method does not close the stream object, thus the caller has to call the close method on it.
reader - The source object from where read the first 'n' linesn - The number of lines to readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.CharSequence object Read the top from the beginning of a File object, stopping as soon as
'n' lines has been read.
file - The source file from where read the first 'n' linesn - The number of lines to readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.CharSequence object Read the top from the beginning of a Path object, stopping as soon as
'n' lines has been read.
path - The source file from where read the first 'n' linesn - The number of lines to readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.CharSequence objectReturns the time that the file denoted by this abstract pathname was last modified.
Where it is required to distinguish an I/O exception from the case
where 0L is returned, or where several attributes of the
same file are required at the same time, or where the time of last
access or the creation time are required, then the java.nio.file.Files#readAttributes(Path,Class,LinkOption[]) method may be used.
long value representing the time the file was
last modified, measured in milliseconds since the epoch
(00:00:00 GMT, January 1, 1970), or 0L if the
file does not exist or if an I/O error occurs List the content of a given path folder. The method is semantically
equivalent to File#list()
self - The folder to listnull if the path is not a folder List the content of a given path folder. The method is semantically
equivalent to File#listFiles()
self - The folder to listPath or null if the path is not a folderCreates the directory named by this abstract pathname
self - The directory to be createdattr
- an optional list of file attributes to set atomically when
creating the directorytrue if the directory is created successfully, or false otherwiseCreates the directory named by this abstract pathname, including any necessary but nonexistent parent directories
self - The path to be createdattr
- an optional list of file attributes to set atomically when
creating the directorytrue if the directory is created successfully, or false otherwiseMake a symbolic or a hard file system link
existing - The existing fileopts
- Optional parameters:
hard: when true create a hard link, otherwise it creates a symbolic link
overwritelink - The java.nio.file.Path of the link to createMove a file or a directory. Mimics the Linux *mv* command
Move a file or a directory. Mimics the Linux *mv* command
Move a file or a directory. Mimics the Linux *mv* command
Resolve a symbolic link to the actual target file, in a similar manner to the
Linux readlink -f command.
It canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist.
Roll a file moving to a new path whose name ends with .1
self - The file itselfmaxRolls - Max number of time to apply the file rolling (i.e. rename to a new name)Sets the owner's or everybody's execute permission for the specified file.
self - The Path for which set the permissionsexecutable
- If true, sets the access permission to allow execute
operations; if false to disallow execute operationsownerOnly
- If true, the execute permission applies only to the
owner's execute permission; otherwise, it applies to everybody.
If the underlying file system can not distinguish the owner's
execute permission from that of others, then the permission will
apply to everybody, regardless of this value.true if and only if the operation succeeded. The
operation will fail if the user does not have permission to
change the access permissions of this file. Sets the last-modified time of the file or directory named by this
Path.
self - The Path to which set the last modified timetime - The new last-modified time, measured in milliseconds since
the epoch (00:00:00 GMT, January 1, 1970)true if and only if the operation succeeded;
false otherwise Set the file Unix permissions using a string like rw-r--r--
self - The Path file for which set the permissions.permissions - The permissions string e.g. rw-r--r--. It must contain 9 letters. Set the file Unix permissions using a string like rw-r--r--
self - The File object for which set the permissions.permissions - The permissions string e.g. rw-r--r--. It must contain 9 letters.Set the file Unix permission using the digit representing the respectively the permissions for the owner, the group and others.
self - The Path file for which set the permissionsowner - The owner permissions using a octal numeric representation.group - The group permissions using a octal numeric representation.other - The others permissions using a octal numeric representation.Set the file Unix permission using the digit representing the respectively the permissions for the owner, the group and others.
self - The File object for which set the permissionsowner - The owner permissions using a octal numeric representation.group - The group permissions using a octal numeric representation.other - The others permissions using a octal numeric representation.* Marks the file or directory named by this abstract pathname so that only read operations are allowed.
A convenience method to set the owner's read permission for the specified file
self - The Path for which set the readable permissionsreadable
- If true, sets the access permission to allow read
operations; if false to disallow read operationsownerOnly
- If true, sets the access permission to allow read
operations; if false to disallow read operationstrue if and only if the operation succeeded. The
operation will fail if the user does not have permission to
change the access permissions of this file.Sets the owner's or everybody's write permission for the specified file.
self - The Path for which set the permissionswritable
- If true, sets the access permission to allow write
operations; if false to disallow write operationsownerOnly
- If true, the write permission applies only to the
owner's write permission; otherwise, it applies to everybody. If
the underlying file system can not distinguish the owner's write
permission from that of others, then the permission will apply to
everybody, regardless of this value.true if and only if the operation succeeded. Read the last 'n' lines from a SeekableByteChannel without reading the previous content.
The method does not close the channel object, thus the caller has to close it.
channel - The channel from where read the ending linesn - The number of lines to be readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.blockSize - The size of the block read when reading the channel tailCharSequence object Read the last 'n' lines from a Path without reading all the file content
channel - The channel from where read the ending linesn - The number of lines to be readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.blockSize - The size of the block read when reading the channel tailCharSequence object Read the last 'n' lines from a Path without reading all the file content
channel - The channel from where read the ending linesn - The number of lines to be readCharSequence object Read the last 'n' lines from a File without reading all the file content
channel - The channel from where read the ending linesn - The number of lines to be readcharset - The charset to use, it can be specified by using a string e.g. 'UTF-8' or a Charset object.
When null is specified the current default charset is used.blockSize - The size of the block read when reading the channel tailCharSequence object