public class File
extends Object
GDK enhancements for File.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
append(Object text)Append the text at the end of the File without writing a BOM. |
|
public void |
append(Object text, boolean writeBom)Append the text at the end of the File. |
|
public void |
append(Reader reader)Append the text supplied by the Writer at the end of the File without writing a BOM. |
|
public void |
append(Writer writer)Append the text supplied by the Writer at the end of the File without writing a BOM. |
|
public void |
append(Writer writer, boolean writeBom)Append the text supplied by the Writer at the end of the File. |
|
public void |
append(byte[] bytes)Append bytes to the end of a File. |
|
public void |
append(InputStream stream)Append binary data to the file. |
|
public void |
append(Object text, String charset)Append the text at the end of the File without writing a BOM, using a specified encoding. |
|
public void |
append(Object text, String charset, boolean writeBom)Append the text at the end of the File, using a specified encoding. |
|
public void |
append(Writer writer, String charset)Append the text supplied by the Writer at the end of the File without writing a BOM, using a specified encoding. |
|
public void |
append(Writer writer, String charset, boolean writeBom)Append the text supplied by the Writer at the end of the File, using a specified encoding. |
|
public void |
append(Reader reader, boolean writeBom)Append the text supplied by the Reader at the end of the File, using a specified encoding. |
|
public void |
append(Reader reader, String charset)Append the text supplied by the Reader at the end of the File without writing a BOM, using a specified encoding. |
|
public void |
append(Reader reader, String charset, boolean writeBom)Append the text supplied by the Reader at the end of the File, using a specified encoding. |
|
public boolean |
asBoolean()Coerce the file to a boolean value. |
<T> |
public T |
asType(Class<T> c)Converts this File to a Writable or delegates to default DefaultGroovyMethods#asType(java.lang.Object, java.lang.Class). |
|
public File |
asWritable()Converts this File to a Writable. |
|
public File |
asWritable(String encoding)Allows a file to return a Writable implementation that can output itself to a Writer stream. |
|
public File |
createParentDirectories()Creates, if needed, any parent directories for this File. |
|
public static File |
createTempDir(File self) |
|
public static File |
createTempDir(File self, String prefix) |
|
public static File |
createTempDir(File self, String prefix, String suffix) |
|
public boolean |
deleteDir()Deletes a directory with all contained files and subdirectories. |
|
public long |
directorySize()Calculates directory size as total size of all its files, recursively. |
|
public void |
eachByte(Closure closure)Traverse through each byte of this File |
|
public void |
eachByte(int bufferLen, Closure closure)Traverse through the bytes of this File, bufferLen bytes at a time. |
|
public void |
eachDir(Closure closure)Invokes the closure for each subdirectory in this directory, ignoring regular files. |
|
public void |
eachDirMatch(Object nameFilter, Closure closure)Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
public void |
eachDirRecurse(Closure closure)Recursively processes each descendant subdirectory in this directory. |
|
public void |
eachFile(FileType fileType, Closure closure)Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
public void |
eachFile(Closure closure)Invokes the closure for each 'child' file in this 'parent' folder/directory. |
|
public void |
eachFileMatch(FileType fileType, Object nameFilter, Closure closure)Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
public void |
eachFileMatch(Object nameFilter, Closure closure)Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. |
|
public void |
eachFileRecurse(FileType fileType, Closure closure)Processes each descendant file in this directory and any subdirectories. |
|
public void |
eachFileRecurse(Closure closure)Processes each descendant file in this directory and any subdirectories. |
<T> |
public T |
eachLine(Closure<T> closure)Iterates through this file line by line. |
<T> |
public T |
eachLine(String charset, Closure<T> closure)Iterates through this file line by line. |
<T> |
public T |
eachLine(int firstLine, Closure<T> closure)Iterates through this file line by line. |
<T> |
public T |
eachLine(String charset, int firstLine, Closure<T> closure)Iterates through this file line by line. |
|
public void |
eachObject(Closure closure)Iterates through the given file object by object. |
|
public Writable |
filterLine(Closure closure)Filters the lines of a File and creates a Writable in return to stream the filtered lines. |
|
public Writable |
filterLine(String charset, Closure closure)Filters the lines of a File and creates a Writable in return to stream the filtered lines. |
|
public void |
filterLine(Writer writer, Closure closure)Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
public void |
filterLine(Writer writer, String charset, Closure closure)Filter the lines from this File, and write them to the given writer based on the given closure predicate. |
|
public String |
getBaseName()Provide the file's name without an extension. |
|
public byte[] |
getBytes()Read the content of the File and returns it as a byte[]. |
|
public String |
getExtension()Provide the extension of this file. |
|
public String |
getText(String charset)Read the content of the File using the specified encoding and return it as a String. |
|
public String |
getText()Read the content of the File and returns it as a String. |
|
public File |
leftShift(Object text)Write the text to the File. |
|
public File |
leftShift(byte[] bytes)Write bytes to a File. |
|
public File |
leftShift(InputStream data)Append binary data to the file. |
|
public DataInputStream |
newDataInputStream()Create a data input stream for this file |
|
public DataOutputStream |
newDataOutputStream()Creates a new data output stream for this file. |
|
public BufferedInputStream |
newInputStream()Creates a buffered input stream for this file. |
|
public ObjectInputStream |
newObjectInputStream()Create an object input stream for this file. |
|
public ObjectInputStream |
newObjectInputStream(ClassLoader classLoader)Create an object input stream for this file using the given class loader. |
|
public ObjectOutputStream |
newObjectOutputStream()Create an object output stream for this file. |
|
public BufferedOutputStream |
newOutputStream()Create a buffered output stream for this file. |
|
public PrintWriter |
newPrintWriter()Create a new PrintWriter for this file. |
|
public PrintWriter |
newPrintWriter(String charset)Create a new PrintWriter for this file, using specified charset. |
|
public BufferedReader |
newReader()Create a buffered reader for this file. |
|
public BufferedReader |
newReader(String charset)Create a buffered reader for this file, using the specified charset as the encoding. |
|
public BufferedWriter |
newWriter()Create a buffered writer for this file. |
|
public BufferedWriter |
newWriter(boolean append)Creates a buffered writer for this file, optionally appending to the existing file content. |
|
public BufferedWriter |
newWriter(String charset, boolean append)Helper method to create a buffered writer for a file without writing a BOM. |
|
public BufferedWriter |
newWriter(String charset, boolean append, boolean writeBom)Helper method to create a buffered writer for a file. |
|
public BufferedWriter |
newWriter(String charset)Creates a buffered writer for this file, writing data without writing a BOM, using a specified encoding. |
|
public byte[] |
readBytes()Reads the content of the file into a byte array. |
|
public List<String> |
readLines()Reads the file into a list of Strings, with one item for each line. |
|
public List<String> |
readLines(String charset)Reads the file into a list of Strings, with one item for each line. |
|
public String |
relativePath(File to)Relative path to file. |
|
public boolean |
renameTo(String newPathName)Renames the file. |
|
public void |
setBytes(byte[] bytes)Write the bytes from the byte array to the File. |
|
public void |
setText(String text)Synonym for write(text) allowing file.text = 'foo'. |
|
public void |
setText(String text, String charset)Synonym for write(text, charset) allowing:
or with some help from ExpandoMetaClass, you could do something like:
|
|
public long |
size()Provide the standard Groovy size() method for File. |
<T> |
public T |
splitEachLine(String regex, Closure<T> closure)Iterates through this file line by line, splitting each line using the given regex separator. |
<T> |
public T |
splitEachLine(Pattern pattern, Closure<T> closure)Iterates through this file line by line, splitting each line using the given separator Pattern. |
<T> |
public T |
splitEachLine(String regex, String charset, Closure<T> closure)Iterates through this file line by line, splitting each line using the given regex separator. |
<T> |
public T |
splitEachLine(Pattern pattern, String charset, Closure<T> closure)Iterates through this file line by line, splitting each line using the given regex separator Pattern. |
|
public void |
traverse(Map<String, ?> options, Closure closure)Processes each descendant file in this directory and any subdirectories. |
|
public void |
traverse(Closure closure)Processes each descendant file in this directory and any subdirectories. |
|
public void |
traverse(Map<String, ?> options)Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. |
<T> |
public T |
withDataInputStream(Closure<T> closure)Create a new DataInputStream for this file and passes it into the closure. |
<T> |
public T |
withDataOutputStream(Closure<T> closure)Create a new DataOutputStream for this file and passes it into the closure. |
|
public Object |
withInputStream(Closure closure)Create a new InputStream for this file and passes it into the closure. |
<T> |
public T |
withObjectInputStream(Closure<T> closure)Create a new ObjectInputStream for this file and pass it to the closure. |
<T> |
public T |
withObjectInputStream(ClassLoader classLoader, Closure<T> closure)Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. |
<T> |
public T |
withObjectOutputStream(Closure<T> closure)Create a new ObjectOutputStream for this file and then pass it to the closure. |
|
public Object |
withOutputStream(Closure closure)Creates a new OutputStream for this file and passes it into the closure. |
<T> |
public T |
withPrintWriter(Closure<T> closure)Create a new PrintWriter for this file which is then passed it into the given closure. |
<T> |
public T |
withPrintWriter(String charset, Closure<T> closure)Create a new PrintWriter with a specified charset for this file. |
<T> |
public T |
withReader(Closure<T> closure)Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns. |
<T> |
public T |
withReader(String charset, Closure<T> closure)Create a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns. |
<T> |
public T |
withWriter(Closure<T> closure)Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
<T> |
public T |
withWriter(String charset, Closure<T> closure)Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. |
<T> |
public T |
withWriterAppend(String charset, Closure<T> closure)Create a new BufferedWriter which will append to this file. |
<T> |
public T |
withWriterAppend(Closure<T> closure)Create a new BufferedWriter for this file in append mode. |
|
public void |
write(String text)Write the text to the File without writing a BOM. |
|
public void |
write(String text, boolean writeBom)Write the text to the File. |
|
public void |
write(String text, String charset)Write the text to the File without writing a BOM, using the specified encoding. |
|
public void |
write(String text, String charset, boolean writeBom)Write the text to the File, using the specified encoding. |
| Methods inherited from class | Name |
|---|---|
class Object |
addShutdownHook, any, any, asBoolean, asType, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits |
Append the text at the end of the File without writing a BOM.
text - the text to append at the end of the File Append the text at the end of the File. If the default
charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and
writeBom is true, the requisite byte order
mark is written to the file before the text.
text - the text to append at the end of the FilewriteBom - whether to write a BOMAppend the text supplied by the Writer at the end of the File without writing a BOM.
reader - the Reader supplying the text to append at the end of the FileAppend the text supplied by the Writer at the end of the File without writing a BOM.
writer - the Writer supplying the text to append at the end of the File Append the text supplied by the Writer at the end of the File. If the default
charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and
writeBom is true, the requisite byte order
mark is written to the file before the text.
writer - the Writer supplying the text to append at the end of the FilewriteBom - whether to write a BOMAppend bytes to the end of a File. It will not be interpreted as text.
bytes - the byte array to append to the end of the FileAppend binary data to the file. It will not be interpreted as text.
stream - stream to read data from.Append the text at the end of the File without writing a BOM, using a specified encoding.
text - the text to append at the end of the Filecharset - the charset used Append the text at the end of the File, using a specified encoding. If
the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias),
writeBom is true, and the file doesn't already
exist, the requisite byte order mark is written to the file before the
text is appended.
text - the text to append at the end of the Filecharset - the charset usedwriteBom - whether to write a BOMAppend the text supplied by the Writer at the end of the File without writing a BOM, using a specified encoding.
writer - the Writer supplying the text to append at the end of the Filecharset - the charset used Append the text supplied by the Writer at the end of the File, using a specified encoding.
If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias),
writeBom is true, and the file doesn't already
exist, the requisite byte order mark is written to the file before the
text is appended.
writer - the Writer supplying the text to append at the end of the Filecharset - the charset usedwriteBom - whether to write a BOM Append the text supplied by the Reader at the end of the File, using a specified encoding.
If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias),
writeBom is true, and the file doesn't already
exist, the requisite byte order mark is written to the file before the
text is appended.
reader - the Reader supplying the text to append at the end of the FilewriteBom - whether to write a BOMAppend the text supplied by the Reader at the end of the File without writing a BOM, using a specified encoding.
reader - the Reader supplying the text to append at the end of the Filecharset - the charset used Append the text supplied by the Reader at the end of the File, using a specified encoding.
If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias),
writeBom is true, and the file doesn't already
exist, the requisite byte order mark is written to the file before the
text is appended.
reader - the Reader supplying the text to append at the end of the Filecharset - the charset usedwriteBom - whether to write a BOM Coerce the file to a boolean value.
true if the file exists, false otherwiseConverts this File to a Writable or delegates to default DefaultGroovyMethods#asType(java.lang.Object, java.lang.Class).
c - the desired classConverts this File to a Writable.
Allows a file to return a Writable implementation that can output itself to a Writer stream.
encoding - the encoding to be used when reading the file's contentsCreates, if needed, any parent directories for this File.
Deletes a directory with all contained files and subdirectories.
The method returns
Calculates directory size as total size of all its files, recursively.
Traverse through each byte of this File
closure - a closureTraverse through the bytes of this File, bufferLen bytes at a time.
bufferLen - the length of the buffer to use.closure - a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.Invokes the closure for each subdirectory in this directory, ignoring regular files.
closure - a closure (the parameter passed is the subdirectory file)Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Only subdirectories are matched; regular files are ignored.
nameFilter - the nameFilter to perform on the name of the directory (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)closure - the closure to invoke Recursively processes each descendant subdirectory in this directory.
Processing consists of calling closure passing it the current
subdirectory and then recursively processing that subdirectory.
Regular files are ignored during traversal.
closure - a closureInvokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories can be processed depending on the fileType enum value.
fileType - if normal files or directories or both should be processedclosure - the closure to invokeInvokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories are processed.
closure - a closure (the parameter passed is the 'child' file)Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Both regular files and subdirectories may be candidates for matching depending on the value of fileType.
// collect names of files in baseDir matching supplied regex pattern
import static groovy.io.FileType.*
def names = []
baseDir.eachFileMatch FILES, ~/foo\d\.txt/, { names << it.name }
assert names == ['foo1.txt', 'foo2.txt']
// remove all *.bak files in baseDir
baseDir.eachFileMatch FILES, ~/.*\.bak/, { File bak -> bak.delete() }
// print out files > 4K in size from baseDir
baseDir.eachFileMatch FILES, { new File(baseDir, it).size() > 4096 }, { println "$it.name ${it.size()}" }
fileType - whether normal files or directories or both should be processednameFilter - the filter to perform on the name of the file/directory (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)closure - the closure to invokeInvokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Both regular files and subdirectories are matched.
nameFilter - the nameFilter to perform on the name of the file (using the DefaultGroovyMethods#isCase(java.lang.Object, java.lang.Object) method)closure - the closure to invoke Processes each descendant file in this directory and any subdirectories.
Processing consists of potentially calling closure passing it the current
file (which may be a normal file or subdirectory) and then if a subdirectory was encountered,
recursively processing the subdirectory. Whether the closure is called is determined by whether
the file was a normal file or subdirectory and the value of fileType.
fileType - if normal files or directories or both should be processedclosure - the closure to invoke on each file Processes each descendant file in this directory and any subdirectories.
Processing consists of calling closure passing it the current
file (which may be a normal file or subdirectory) and then if a subdirectory was encountered,
recursively processing the subdirectory.
closure - a ClosureIterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
charset - opens the file with a specified charsetclosure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure - a closure (arg 1 is line, optional arg 2 is line number)Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
charset - opens the file with a specified charsetfirstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure - a closure (arg 1 is line, optional arg 2 is line number)Iterates through the given file object by object.
closure - a closureFilters the lines of a File and creates a Writable in return to stream the filtered lines.
self is not readableclosure - a closure which returns a boolean indicating to filter
the line or notFilters the lines of a File and creates a Writable in return to stream the filtered lines.
charset - opens the file with a specified charsetclosure - a closure which returns a boolean indicating to filter
the line or notFilter the lines from this File, and write them to the given writer based on the given closure predicate.
self is not readablewriter - a writer destination to write filtered lines toclosure - a closure which takes each line as a parameter and returns
true if the line should be written to this writer.Filter the lines from this File, and write them to the given writer based on the given closure predicate.
writer - a writer destination to write filtered lines tocharset - opens the file with a specified charsetclosure - a closure which takes each line as a parameter and returns
true if the line should be written to this writer.Provide the file's name without an extension.
Read the content of the File and returns it as a byte[].
Provide the extension of this file.
Read the content of the File using the specified encoding and return it as a String.
charset - the charset used to read the content of the fileRead the content of the File and returns it as a String.
Write the text to the File.
text - the text to write to the FileWrite bytes to a File.
bytes - the byte array to append to the end of the FileAppend binary data to the file. See File.append
data - an InputStream of data to write to the fileCreate a data input stream for this file
Creates a new data output stream for this file.
Creates a buffered input stream for this file.
Create an object input stream for this file.
Create an object input stream for this file using the given class loader.
classLoader - the class loader to use when loading the classCreate an object output stream for this file.
Create a buffered output stream for this file.
Create a new PrintWriter for this file.
Create a new PrintWriter for this file, using specified charset. If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the requisite byte order mark is written to the stream before the writer is returned.
charset - the charsetCreate a buffered reader for this file.
Create a buffered reader for this file, using the specified charset as the encoding.
charset - the charset for this FileCreate a buffered writer for this file.
Creates a buffered writer for this file, optionally appending to the existing file content.
append - true if data should be appended to the fileHelper method to create a buffered writer for a file without writing a BOM.
charset - the name of the encoding used to write in this fileappend - true if in append modeHelper method to create a buffered writer for a file. If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the requisite byte order mark is written to the stream before the writer is returned.
charset - the name of the encoding used to write in this fileappend - true if in append modewriteBom - whether to write a BOMCreates a buffered writer for this file, writing data without writing a BOM, using a specified encoding.
charset - the name of the encoding used to write in this fileReads the content of the file into a byte array.
Reads the file into a list of Strings, with one item for each line.
Reads the file into a list of Strings, with one item for each line.
charset - opens the file with a specified charsetRelative path to file.
to - the File to calculate the path toRenames the file. It's a shortcut for File.renameTo
newPathName - The new pathname for the named filetrue if and only if the renaming succeeded;
false otherwiseWrite the bytes from the byte array to the File.
bytes - the byte[] to write to the fileSynonym for write(text) allowing file.text = 'foo'.
text - the text to write to the FileSynonym for write(text, charset) allowing:
myFile.setText('some text', charset)
or with some help from ExpandoMetaClass, you could do something like:
myFile.metaClass.setText = { String s -> delegate.setText(s, 'UTF-8') }
myfile.text = 'some text'
charset - The charset used when writing to the filetext - The text to write to the File Provide the standard Groovy size() method for File.
Iterates through this file line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
regex - the delimiting regular expressionclosure - a closureIterates through this file line by line, splitting each line using the given separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression Pattern. Finally the resources used for processing the file are closed.
pattern - the regular expression Pattern for the delimiterclosure - a closureIterates through this file line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
regex - the delimiting regular expressioncharset - opens the file with a specified charsetclosure - a closureIterates through this file line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
pattern - the regular expression Pattern for the delimitercharset - opens the file with a specified charsetclosure - a closure Processes each descendant file in this directory and any subdirectories.
Processing consists of potentially calling closure passing it the current
file (which may be a normal file or subdirectory) and then if a subdirectory was encountered,
recursively processing the subdirectory.
The traversal can be adapted by providing various options in the options Map according
to the following keys:
def totalSize = 0
def count = 0
def sortByTypeThenName = { a, b ->
a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : a.name <=> b.name
}
rootDir.traverse(
type : FILES,
nameFilter : ~/.*\.groovy/,
preDir : { if (it.name == '.svn') return SKIP_SUBTREE },
postDir : { println "Found $count files in $it.name totalling $totalSize bytes"
totalSize = 0; count = 0 },
postRoot : true
sort : sortByTypeThenName
) {it -> totalSize += it.size(); count++ }
options - a Map of options to alter the traversal behaviorclosure - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value
which can be used to control subsequent processingProcesses each descendant file in this directory and any subdirectories. Convenience method for File.traverse when no options to alter the traversal behavior are required.
closure - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value
which can be used to control subsequent processingInvokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. Convenience method for File.traverse allowing the 'visit' closure to be included in the options Map rather than as a parameter.
options - a Map of options to alter the traversal behaviorCreate a new DataInputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreate a new DataOutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreate a new InputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreate a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreate a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. This method ensures the stream is closed after the closure returns.
classLoader - the class loader to use when loading the classclosure - a closureCreate a new ObjectOutputStream for this file and then pass it to the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreates a new OutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
closure - a closureCreate a new PrintWriter for this file which is then passed it into the given closure. This method ensures the writer is closed after the closure returns.
closure - the closure to invoke with the PrintWriterCreate a new PrintWriter with a specified charset for this file. If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the requisite byte order mark is written to the stream when the writer is created. The writer is passed to the closure, and will be closed before this method returns.
charset - the charsetclosure - the closure to invoke with the PrintWriterCreate a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns.
closure - a closureCreate a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns.
charset - the charset for this input streamclosure - a closureCreates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.
closure - a closureCreates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. The writer will use the given charset encoding. If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the requisite byte order mark is written to the stream when the writer is created.
charset - the charset usedclosure - a closureCreate a new BufferedWriter which will append to this file. If the given charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the requisite byte order mark is written to the stream when the writer is created. The writer is passed to the closure and will be closed before this method returns.
charset - the charset usedclosure - a closureCreate a new BufferedWriter for this file in append mode. The writer is passed to the closure and is closed after the closure returns.
closure - a closureWrite the text to the File without writing a BOM.
text - the text to write to the File Write the text to the File. If the default charset is
"UTF-16BE" or "UTF-16LE" (or an equivalent alias) and
writeBom is true, the requisite byte order
mark is written to the file before the text.
text - the text to write to the FilewriteBom - whether to write a BOMWrite the text to the File without writing a BOM, using the specified encoding.
text - the text to write to the Filecharset - the charset used Write the text to the File, using the specified encoding. If the given
charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and
writeBom is true, the requisite byte order
mark is written to the file before the text.
text - the text to write to the Filecharset - the charset usedwriteBom - whether to write a BOM