Groovy Documentation

## org.codehaus.groovy.runtime
[Java] Class ResourceGroovyMethods

    java.lang.Object
      org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
          org.codehaus.groovy.runtime.ResourceGroovyMethods

    public class ResourceGroovyMethods
    extends DefaultGroovyMethodsSupport

This class defines new groovy methods for Readers, Writers, InputStreams and OutputStreams which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter being the destination class, i.e. `public static T eachLine(InputStream self, Closure c)` provides a `eachLine(Closure c)` method for `InputStream`.

NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

Authors:
  James Strachan
  Jeremy Rayner
  Sam Pullara
  Rod Cope
  Guillaume Laforge
  John Wilson
  Hein Meling
  Dierk Koenig
  Pilho Kim
  Marc Guillemot
  Russel Winder
  bing ran
  Jochen Theodorou
  Paul King
  Michael Baehr
  Joachim Baumann
  Alex Tkachman
  Ted Naleid
  Brad Long
  Jim Jagielski
  Rodolfo Velasco
  jeremi Joslin
  Hamlet D'Arcy
  Cedric Champeau
  Tim Yates
  Dinko Srkoc

Method Summary
`static void` | `append(java.io.File file, java.lang.Object text)` Append the text at the end of the File.
`static void` | `append(java.io.File file, byte[] bytes)` Append bytes to the end of a File.
`static void` | `append(java.io.File self, java.io.InputStream stream)` Append binary data to the file.
`static void` | `append(java.io.File file, java.lang.Object text, java.lang.String charset)` Append the text at the end of the File, using a specified encoding.
`static java.lang.Object` | `asType(java.io.File f, java.lang.Class c)`
`static java.io.File` | `asWritable(java.io.File file)`
`static java.io.File` | `asWritable(java.io.File file, java.lang.String encoding)` Allows a file to return a Writable implementation that can output itself to a Writer stream.
`static boolean` | `deleteDir(java.io.File self)`
`static void` | `eachByte(java.io.File self, Closure closure)`
`static void` | `eachByte(java.io.File self, int bufferLen, Closure closure)`
`static void` | `eachByte(java.net.URL url, Closure closure)`
`static void` | `eachByte(java.net.URL url, int bufferLen, Closure closure)`
`static void` | `eachDir(java.io.File self, Closure closure)` Invokes the closure for each subdirectory in this directory, ignoring regular files.
`static void` | `eachDirMatch(java.io.File self, java.lang.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 method to determine if a match occurs.
`static void` | `eachDirRecurse(java.io.File self, Closure closure)` Invokes the closure for each descendant directory of this directory.
`static void` | `eachFile(java.io.File self, FileType fileType, Closure closure)` Invokes the closure for each 'child' file in this 'parent' folder/directory.
`static void` | `eachFile(java.io.File self, Closure closure)` Invokes the closure for each 'child' file in this 'parent' folder/directory.
`static void` | `eachFileMatch(java.io.File self, FileType fileType, java.lang.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 method to determine if a match occurs.
`static void` | `eachFileMatch(java.io.File self, java.lang.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 method to determine if a match occurs.
`static void` | `eachFileRecurse(java.io.File self, FileType fileType, Closure closure)` Invokes the closure for each descendant file in this directory.
`static void` | `eachFileRecurse(java.io.File self, Closure closure)` Invokes the closure for each descendant file in this directory.
`static java.lang.Object` | `eachLine(java.io.File self, Closure closure)` Iterates through this file line by line.
`static java.lang.Object` | `eachLine(java.io.File self, java.lang.String charset, Closure closure)` Iterates through this file line by line.
`static java.lang.Object` | `eachLine(java.io.File self, int firstLine, Closure closure)` Iterates through this file line by line.
`static java.lang.Object` | `eachLine(java.io.File self, java.lang.String charset, int firstLine, Closure closure)` Iterates through this file line by line.
`static java.lang.Object` | `eachLine(java.net.URL url, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
`static java.lang.Object` | `eachLine(java.net.URL url, int firstLine, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
`static java.lang.Object` | `eachLine(java.net.URL url, java.lang.String charset, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
`static java.lang.Object` | `eachLine(java.net.URL url, java.lang.String charset, int firstLine, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
`static void` | `eachObject(java.io.File self, Closure closure)` Iterates through the given file object by object.
`static Writable` | `filterLine(java.io.File self, Closure closure)`
`static Writable` | `filterLine(java.io.File self, java.lang.String charset, Closure closure)`
`static void` | `filterLine(java.io.File self, java.io.Writer writer, Closure closure)`
`static void` | `filterLine(java.io.File self, java.io.Writer writer, java.lang.String charset, Closure closure)`
`static Writable` | `filterLine(java.net.URL self, Closure predicate)`
`static Writable` | `filterLine(java.net.URL self, java.lang.String charset, Closure predicate)`
`static void` | `filterLine(java.net.URL self, java.io.Writer writer, Closure predicate)`
`static void` | `filterLine(java.net.URL self, java.io.Writer writer, java.lang.String charset, Closure predicate)`
`static byte[]` | `getBytes(java.io.File file)` Read the content of the File and returns it as a byte[].
`static byte[]` | `getBytes(java.net.URL url)` Read the content of this URL and returns it as a byte[].
`static java.lang.String` | `getText(java.io.File file, java.lang.String charset)` Read the content of the File using the specified encoding and return it as a String.
`static java.lang.String` | `getText(java.io.File file)` Read the content of the File and returns it as a String.
`static java.lang.String` | `getText(java.net.URL url)` Read the content of this URL and returns it as a String.
`static java.lang.String` | `getText(java.net.URL url, java.util.Map parameters)` Read the content of this URL and returns it as a String.
`static java.lang.String` | `getText(java.net.URL url, java.lang.String charset)` Read the data from this URL and return it as a String.
`static java.lang.String` | `getText(java.net.URL url, java.util.Map parameters, java.lang.String charset)` Read the data from this URL and return it as a String.
`static java.io.File` | `leftShift(java.io.File file, java.lang.Object text)` Write the text to the File.
`static java.io.File` | `leftShift(java.io.File file, byte[] bytes)` Write bytes to a File.
`static java.io.File` | `leftShift(java.io.File file, java.io.InputStream data)` Append binary data to the file.
`static java.io.DataInputStream` | `newDataInputStream(java.io.File file)`
`static java.io.DataOutputStream` | `newDataOutputStream(java.io.File file)`
`static java.io.BufferedInputStream` | `newInputStream(java.io.File file)`
`static java.io.BufferedInputStream` | `newInputStream(java.net.URL url)` Creates a buffered input stream for this URL.
`static java.io.BufferedInputStream` | `newInputStream(java.net.URL url, java.util.Map parameters)`
`static java.io.ObjectInputStream` | `newObjectInputStream(java.io.File file)` Create an object input stream for this file.
`static java.io.ObjectInputStream` | `newObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader)` Create an object input stream for this file using the given class loader.
`static java.io.ObjectOutputStream` | `newObjectOutputStream(java.io.File file)` Create an object output stream for this file.
`static java.io.BufferedOutputStream` | `newOutputStream(java.io.File file)`
`static java.io.PrintWriter` | `newPrintWriter(java.io.File file)`
`static java.io.PrintWriter` | `newPrintWriter(java.io.File file, java.lang.String charset)`
`static java.io.BufferedReader` | `newReader(java.io.File file)`
`static java.io.BufferedReader` | `newReader(java.io.File file, java.lang.String charset)`
`static java.io.BufferedReader` | `newReader(java.net.URL url)`
`static java.io.BufferedReader` | `newReader(java.net.URL url, java.util.Map parameters)`
`static java.io.BufferedReader` | `newReader(java.net.URL url, java.lang.String charset)`
`static java.io.BufferedReader` | `newReader(java.net.URL url, java.util.Map parameters, java.lang.String charset)`
`static java.io.BufferedWriter` | `newWriter(java.io.File file)`
`static java.io.BufferedWriter` | `newWriter(java.io.File file, boolean append)`
`static java.io.BufferedWriter` | `newWriter(java.io.File file, java.lang.String charset, boolean append)`
`static java.io.BufferedWriter` | `newWriter(java.io.File file, java.lang.String charset)` Creates a buffered writer for this file, writing data using the given encoding.
`static byte[]` | `readBytes(java.io.File file)`
`static java.util.List` | `readLines(java.io.File file)` Reads the file into a list of Strings, with one item for each line.
`static java.util.List` | `readLines(java.io.File file, java.lang.String charset)` Reads the file into a list of Strings, with one item for each line.
`static java.util.List` | `readLines(java.net.URL self)` Reads the URL contents into a list, with one element for each line.
`static java.util.List` | `readLines(java.net.URL self, java.lang.String charset)` Reads the URL contents into a list, with one element for each line.
`static boolean` | `renameTo(java.io.File self, java.lang.String newPathName)` Renames the file.
`static void` | `setBytes(java.io.File file, byte[] bytes)` Write the bytes from the byte array to the File.
`static void` | `setText(java.io.File file, java.lang.String text)` Synonym for write(text) allowing file.text = 'foo'.

`static void`

`setText(java.io.File file, java.lang.String text, java.lang.String charset)`

Synonym 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'

`static long` | `size(java.io.File self)` Provide the standard Groovy `size()` method for `File`.
`static java.lang.Object` | `splitEachLine(java.io.File self, java.lang.String regex, Closure closure)` Iterates through this file line by line, splitting each line using the given regex separator.
`static java.lang.Object` | `splitEachLine(java.io.File self, java.util.regex.Pattern pattern, Closure closure)` Iterates through this file line by line, splitting each line using the given separator Pattern.
`static java.lang.Object` | `splitEachLine(java.io.File self, java.lang.String regex, java.lang.String charset, Closure closure)` Iterates through this file line by line, splitting each line using the given regex separator.
`static java.lang.Object` | `splitEachLine(java.io.File self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure)` Iterates through this file line by line, splitting each line using the given regex separator Pattern.
`static java.lang.Object` | `splitEachLine(java.net.URL self, java.lang.String regex, Closure closure)` Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.
`static java.lang.Object` | `splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, Closure closure)` Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.
`static java.lang.Object` | `splitEachLine(java.net.URL self, java.lang.String regex, java.lang.String charset, Closure closure)` Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.
`static java.lang.Object` | `splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure)` Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.
`static java.net.URI` | `toURI(java.lang.CharSequence self)` Transforms a CharSequence representing a URI into a URI object.
`static java.net.URI` | `toURI(java.lang.String self)`
`static java.net.URL` | `toURL(java.lang.CharSequence self)`
`static java.net.URL` | `toURL(java.lang.String self)`
`static void` | `traverse(java.io.File self, java.util.Map options, Closure closure)` Invokes `closure` for each descendant file in this directory tree.
`static void` | `traverse(java.io.File self, Closure closure)` Invokes the closure for each descendant file in this directory tree.
`static void` | `traverse(java.io.File self, java.util.Map options)` Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree.
`static java.lang.Object` | `withDataInputStream(java.io.File file, Closure closure)`
`static java.lang.Object` | `withDataOutputStream(java.io.File file, Closure closure)`
`static java.lang.Object` | `withInputStream(java.io.File file, Closure closure)`
`static java.lang.Object` | `withInputStream(java.net.URL url, Closure closure)`
`static java.lang.Object` | `withObjectInputStream(java.io.File file, Closure closure)` Create a new ObjectInputStream for this file and pass it to the closure.
`static java.lang.Object` | `withObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader, Closure closure)` Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure.
`static java.lang.Object` | `withObjectOutputStream(java.io.File file, Closure closure)` Create a new ObjectOutputStream for this file and then pass it to the closure.
`static java.lang.Object` | `withOutputStream(java.io.File file, Closure closure)`
`static java.lang.Object` | `withPrintWriter(java.io.File file, Closure closure)`
`static java.lang.Object` | `withPrintWriter(java.io.File file, java.lang.String charset, Closure closure)`
`static java.lang.Object` | `withReader(java.io.File file, Closure closure)`
`static java.lang.Object` | `withReader(java.io.File file, java.lang.String charset, Closure closure)`
`static java.lang.Object` | `withReader(java.net.URL url, Closure closure)`
`static java.lang.Object` | `withReader(java.net.URL url, java.lang.String charset, Closure closure)`
`static java.lang.Object` | `withWriter(java.io.File file, Closure 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.
`static java.lang.Object` | `withWriter(java.io.File file, java.lang.String charset, Closure closure)`
`static java.lang.Object` | `withWriterAppend(java.io.File file, java.lang.String charset, Closure closure)`
`static java.lang.Object` | `withWriterAppend(java.io.File file, Closure closure)`
`static void` | `write(java.io.File file, java.lang.String text)` Write the text to the File.
`static void` | `write(java.io.File file, java.lang.String text, java.lang.String charset)` Write the text to the File, using the specified encoding.

Methods inherited from class DefaultGroovyMethodsSupport
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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()

Method Detail

### append

    public static void append(java.io.File file, java.lang.Object text)

  Append the text at the end of the File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to append at the end of the File
  Since:
    1.0

### append

    public static void append(java.io.File file, byte[] bytes)

  Append bytes to the end of a File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `bytes` - the byte array to append to the end of the File
  Since:
    1.5.1

### append

    public static void append(java.io.File self, java.io.InputStream stream)

  Append binary data to the file. It will not be interpreted as text.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `stream` - stream to read data from.
  Since:
    1.5.0

### append

    public static void append(java.io.File file, java.lang.Object text, java.lang.String charset)

  Append the text at the end of the File, using a specified encoding.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to append at the end of the File
    `charset` - the charset used
  Since:
    1.0

### asType

    /**
    public static java.lang.Object asType(java.io.File f, java.lang.Class c)

### asWritable

    public static java.io.File asWritable(java.io.File file)

### asWritable

    public static java.io.File asWritable(java.io.File file, java.lang.String encoding)

  Allows a file to return a Writable implementation that can output itself to a Writer stream.
  Parameters:
    `file` - a File
    `encoding` - the encoding to be used when reading the file's contents
  Returns:
    File which wraps the input file and which implements Writable
  Since:
    1.0

### deleteDir

    public static boolean deleteDir(java.io.File self)

### eachByte

    public static void eachByte(java.io.File self, Closure closure)

### eachByte

    public static void eachByte(java.io.File self, int bufferLen, Closure closure)

### eachByte

    public static void eachByte(java.net.URL url, Closure closure)

### eachByte

    public static void eachByte(java.net.URL url, int bufferLen, Closure closure)

### eachDir

    public static void eachDir(java.io.File self, Closure closure)

  Invokes the closure for each subdirectory in this directory, ignoring regular files.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a File (that happens to be a folder/directory)
    `closure` - a closure (first parameter is the subdirectory file)
  See Also:
    java.io.File#listFiles()
    eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
  Since:
    1.0

### eachDirMatch

    public static void eachDirMatch(java.io.File self, java.lang.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 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.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a file
    `nameFilter` - the nameFilter to perform on the name of the directory (using the DefaultGroovyMethods.isCase method)
    `closure` - the closure to invoke
  See Also:
    eachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
  Since:
    1.5.0

### eachDirRecurse

    public static void eachDirRecurse(java.io.File self, Closure closure)

  Invokes the closure for each descendant directory of this directory. Sub-directories are recursively searched in a depth-first fashion. Only subdirectories are passed to the closure; regular files are ignored.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a directory
    `closure` - a closure
  See Also:
    eachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
  Since:
    1.5.0

### eachFile

    public static void eachFile(java.io.File self, FileType fileType, Closure closure)

  Invokes 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.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a file object
    `fileType` - if normal files or directories or both should be processed
    `closure` - the closure to invoke
  Since:
    1.7.1

### eachFile

    public static void eachFile(java.io.File self, Closure closure)

  Invokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories are processed.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a File (that happens to be a folder/directory)
    `closure` - a closure (first parameter is the 'child' file)
  See Also:
    java.io.File#listFiles()
    eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
  Since:
    1.5.0

### eachFileMatch

    public static void eachFileMatch(java.io.File self, FileType fileType, java.lang.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 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()}" }

  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a file
    `fileType` - whether normal files or directories or both should be processed
    `nameFilter` - the filter to perform on the name of the file/directory (using the DefaultGroovyMethods.isCase method)
    `closure` - the closure to invoke
  Since:
    1.7.1

### eachFileMatch

    public static void eachFileMatch(java.io.File self, java.lang.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 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.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a file
    `nameFilter` - the nameFilter to perform on the name of the file (using the DefaultGroovyMethods.isCase method)
    `closure` - the closure to invoke
  See Also:
    eachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
  Since:
    1.5.0

### eachFileRecurse

    public static void eachFileRecurse(java.io.File self, FileType fileType, Closure closure)

  Invokes the closure for each descendant file in this directory. Sub-directories are recursively searched in a depth-first fashion. Both regular files and subdirectories may be passed to the closure depending on the value of fileType.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a file object
    `fileType` - if normal files or directories or both should be processed
    `closure` - the closure to invoke on each file
  Since:
    1.7.1

### eachFileRecurse

    public static void eachFileRecurse(java.io.File self, Closure closure)

  Invokes the closure for each descendant file in this directory. Sub-directories are recursively searched in a depth-first fashion. Both regular files and subdirectories are passed to the closure.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a File
    `closure` - a closure
  See Also:
    eachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
  Since:
    1.0

### eachLine

    public static java.lang.Object eachLine(java.io.File self, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `closure` - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
  Returns:
    the last value returned by the closure
  See Also:
    eachLine(java.io.File, int, groovy.lang.Closure)
  Since:
    1.5.5

### eachLine

    public static java.lang.Object eachLine(java.io.File self, java.lang.String charset, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `charset` - opens the file with a specified charset
    `closure` - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
  Returns:
    the last value returned by the closure
  See Also:
    eachLine(java.io.File, java.lang.String, int, groovy.lang.Closure)
  Since:
    1.6.8

### eachLine

    public static java.lang.Object eachLine(java.io.File self, int firstLine, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `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)
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.eachLine
  Since:
    1.5.7

### eachLine

    public static java.lang.Object eachLine(java.io.File self, java.lang.String charset, int firstLine, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `charset` - opens the file with a specified charset
    `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)
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.eachLine
  Since:
    1.6.8

### eachLine

    public static java.lang.Object eachLine(java.net.URL url, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - a URL to open and read
    `closure` - a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
  Returns:
    the last value returned by the closure
  See Also:
    eachLine(java.net.URL, int, groovy.lang.Closure)
  Since:
    1.5.6

### eachLine

    public static java.lang.Object eachLine(java.net.URL url, int firstLine, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - a URL to open and read
    `firstLine` - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
    `closure` - a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.eachLine
  Since:
    1.5.7

### eachLine

    public static java.lang.Object eachLine(java.net.URL url, java.lang.String charset, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - a URL to open and read
    `charset` - opens the stream with a specified charset
    `closure` - a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
  Returns:
    the last value returned by the closure
  See Also:
    eachLine(java.net.URL, java.lang.String, int, groovy.lang.Closure)
  Since:
    1.5.6

### eachLine

    public static java.lang.Object eachLine(java.net.URL url, java.lang.String charset, int firstLine, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - a URL to open and read
    `charset` - opens the stream with a specified charset
    `firstLine` - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
    `closure` - a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.eachLine
  Since:
    1.5.7

### eachObject

    public static void eachObject(java.io.File self, Closure closure)

  Iterates through the given file object by object.
  throws:
    IOException if an IOException occurs.
  throws:
    ClassNotFoundException if the class is not found.
  Parameters:
    `self` - a File
    `closure` - a closure
  See Also:
    IOGroovyMethods.eachObject
  Since:
    1.0

### filterLine

    public static Writable filterLine(java.io.File self, Closure closure)

### filterLine

    public static Writable filterLine(java.io.File self, java.lang.String charset, Closure closure)

### filterLine

    public static void filterLine(java.io.File self, java.io.Writer writer, Closure closure)

### filterLine

    public static void filterLine(java.io.File self, java.io.Writer writer, java.lang.String charset, Closure closure)

### filterLine

    public static Writable filterLine(java.net.URL self, Closure predicate)

### filterLine

    public static Writable filterLine(java.net.URL self, java.lang.String charset, Closure predicate)

### filterLine

    public static void filterLine(java.net.URL self, java.io.Writer writer, Closure predicate)

### filterLine

    public static void filterLine(java.net.URL self, java.io.Writer writer, java.lang.String charset, Closure predicate)

### getBytes

    public static byte[] getBytes(java.io.File file)

  Read the content of the File and returns it as a byte[].
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - the file whose content we want to read
  Returns:
    a String containing the content of the file
  Since:
    1.7.1

### getBytes

    public static byte[] getBytes(java.net.URL url)

  Read the content of this URL and returns it as a byte[].
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - URL to read content from
  Returns:
    the byte[] from that URL
  Since:
    1.7.1

### getText

    public static java.lang.String getText(java.io.File file, java.lang.String charset)

  Read the content of the File using the specified encoding and return it as a String.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - the file whose content we want to read
    `charset` - the charset used to read the content of the file
  Returns:
    a String containing the content of the file
  Since:
    1.0

### getText

    public static java.lang.String getText(java.io.File file)

  Read the content of the File and returns it as a String.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - the file whose content we want to read
  Returns:
    a String containing the content of the file
  Since:
    1.0

### getText

    public static java.lang.String getText(java.net.URL url)

  Read the content of this URL and returns it as a String.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - URL to read content from
  Returns:
    the text from that URL
  Since:
    1.0

### getText

    public static java.lang.String getText(java.net.URL url, java.util.Map parameters)

  Read the content of this URL and returns it as a String.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - URL to read content from
    `parameters` - connection parameters
  Returns:
    the text from that URL
  Since:
    1.8.1

### getText

    public static java.lang.String getText(java.net.URL url, java.lang.String charset)

  Read the data from this URL and return it as a String. The connection stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - URL to read content from
    `charset` - opens the stream with a specified charset
  Returns:
    the text from that URL
  See Also:
    java.net.URLConnection#getInputStream()
  Since:
    1.0

### getText

    public static java.lang.String getText(java.net.URL url, java.util.Map parameters, java.lang.String charset)

  Read the data from this URL and return it as a String. The connection stream is closed before this method returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `url` - URL to read content from
    `parameters` - connection parameters
    `charset` - opens the stream with a specified charset
  Returns:
    the text from that URL
  See Also:
    java.net.URLConnection#getInputStream()
  Since:
    1.8.1

### leftShift

    public static java.io.File leftShift(java.io.File file, java.lang.Object text)

  Write the text to the File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to write to the File
  Returns:
    the original file
  Since:
    1.0

### leftShift

    public static java.io.File leftShift(java.io.File file, byte[] bytes)

  Write bytes to a File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `bytes` - the byte array to append to the end of the File
  Returns:
    the original file
  Since:
    1.5.0

### leftShift

    public static java.io.File leftShift(java.io.File file, java.io.InputStream data)

  Append binary data to the file. See append(java.io.File, java.io.InputStream)
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `data` - an InputStream of data to write to the file
  Returns:
    the file
  Since:
    1.5.0

### newDataInputStream

    public static java.io.DataInputStream newDataInputStream(java.io.File file)

### newDataOutputStream

    public static java.io.DataOutputStream newDataOutputStream(java.io.File file)

### newInputStream

    public static java.io.BufferedInputStream newInputStream(java.io.File file)

### newInputStream

    public static java.io.BufferedInputStream newInputStream(java.net.URL url)

  Creates a buffered input stream for this URL.
  throws:
    MalformedURLException is thrown if the URL is not well formed
  throws:
    IOException if an I/O error occurs while creating the input stream
  Parameters:
    `url` - a URL
  Returns:
    a BufferedInputStream for the URL
  Since:
    1.5.2

### newInputStream

    public static java.io.BufferedInputStream newInputStream(java.net.URL url, java.util.Map parameters)

### newObjectInputStream

    public static java.io.ObjectInputStream newObjectInputStream(java.io.File file)

  Create an object input stream for this file.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a file
  Returns:
    an object input stream
  Since:
    1.5.0

### newObjectInputStream

    public static java.io.ObjectInputStream newObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader)

  Create an object input stream for this file using the given class loader.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a file
    `classLoader` - the class loader to use when loading the class
  Returns:
    an object input stream
  Since:
    1.5.0

### newObjectOutputStream

    public static java.io.ObjectOutputStream newObjectOutputStream(java.io.File file)

  Create an object output stream for this file.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a file
  Returns:
    an object output stream
  Since:
    1.5.0

### newOutputStream

    public static java.io.BufferedOutputStream newOutputStream(java.io.File file)

### newPrintWriter

    public static java.io.PrintWriter newPrintWriter(java.io.File file)

### newPrintWriter

    public static java.io.PrintWriter newPrintWriter(java.io.File file, java.lang.String charset)

### newReader

    public static java.io.BufferedReader newReader(java.io.File file)

### newReader

    public static java.io.BufferedReader newReader(java.io.File file, java.lang.String charset)

### newReader

    public static java.io.BufferedReader newReader(java.net.URL url)

### newReader

    public static java.io.BufferedReader newReader(java.net.URL url, java.util.Map parameters)

### newReader

    public static java.io.BufferedReader newReader(java.net.URL url, java.lang.String charset)

### newReader

    public static java.io.BufferedReader newReader(java.net.URL url, java.util.Map parameters, java.lang.String charset)

### newWriter

    public static java.io.BufferedWriter newWriter(java.io.File file)

### newWriter

    public static java.io.BufferedWriter newWriter(java.io.File file, boolean append)

### newWriter

    public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset, boolean append)

### newWriter

    public static java.io.BufferedWriter newWriter(java.io.File file, java.lang.String charset)

  Creates a buffered writer for this file, writing data using the given encoding.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `charset` - the name of the encoding used to write in this file
  Returns:
    a BufferedWriter
  Since:
    1.0

### readBytes

    public static byte[] readBytes(java.io.File file)

### readLines

    public static java.util.List readLines(java.io.File file)

  Reads the file into a list of Strings, with one item for each line.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
  Returns:
    a List of lines
  See Also:
    IOGroovyMethods.readLines
  Since:
    1.0

### readLines

    public static java.util.List readLines(java.io.File file, java.lang.String charset)

  Reads the file into a list of Strings, with one item for each line.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `charset` - opens the file with a specified charset
  Returns:
    a List of lines
  See Also:
    IOGroovyMethods.readLines
  Since:
    1.6.8

### readLines

    public static java.util.List readLines(java.net.URL self)

  Reads the URL contents into a list, with one element for each line.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a URL
  Returns:
    a List of lines
  See Also:
    IOGroovyMethods.readLines
  Since:
    1.6.8

### readLines

    public static java.util.List readLines(java.net.URL self, java.lang.String charset)

  Reads the URL contents into a list, with one element for each line.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a URL
    `charset` - opens the URL with a specified charset
  Returns:
    a List of lines
  See Also:
    IOGroovyMethods.readLines
  Since:
    1.6.8

### renameTo

    public static boolean renameTo(java.io.File self, java.lang.String newPathName)

  Renames the file. It's a shortcut for java.io.File#renameTo(File)
  Parameters:
    `self` - a File
    `newPathName` - The new pathname for the named file
  Returns:
    `true` if and only if the renaming succeeded; `false` otherwise
  Since:
    1.7.4

### setBytes

    public static void setBytes(java.io.File file, byte[] bytes)

  Write the bytes from the byte array to the File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - the file to write to
    `bytes` - the byte[] to write to the file
  Since:
    1.7.1

### setText

    public static void setText(java.io.File file, java.lang.String text)

  Synonym for write(text) allowing file.text = 'foo'.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to write to the File
  See Also:
    write(java.io.File, java.lang.String)
  Since:
    1.5.1

### setText

    public static void setText(java.io.File file, java.lang.String text, java.lang.String charset)

  Synonym 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'

  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - A File
    `charset` - The charset used when writing to the file
    `text` - The text to write to the File
  See Also:
    write(java.io.File, java.lang.String, java.lang.String)
  Since:
    1.7.3

### size

    public static long size(java.io.File self)

  Provide the standard Groovy `size()` method for `File`.
  Parameters:
    `self` - a file object
  Returns:
    the file's size (length)
  Since:
    1.5.0

### splitEachLine

    public static java.lang.Object splitEachLine(java.io.File self, java.lang.String regex, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  throws:
    java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
  Parameters:
    `self` - a File
    `regex` - the delimiting regular expression
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.5.5

### splitEachLine

    public static java.lang.Object splitEachLine(java.io.File self, java.util.regex.Pattern pattern, Closure closure)

  Iterates 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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `pattern` - the regular expression Pattern for the delimiter
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.io.File self, java.lang.String regex, java.lang.String charset, Closure closure)

  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.
  throws:
    IOException if an IOException occurs.
  throws:
    java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
  Parameters:
    `self` - a File
    `regex` - the delimiting regular expression
    `charset` - opens the file with a specified charset
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.io.File self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure)

  Iterates 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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a File
    `pattern` - the regular expression Pattern for the delimiter
    `charset` - opens the file with a specified charset
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.net.URL self, java.lang.String regex, Closure closure)

  Iterates through the input stream associated with this URL 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 URL are closed.
  throws:
    IOException if an IOException occurs.
  throws:
    java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
  Parameters:
    `self` - a URL to open and read
    `regex` - the delimiting regular expression
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, Closure closure)

  Iterates through the input stream associated with this URL 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 URL are closed.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a URL to open and read
    `pattern` - the regular expression Pattern for the delimiter
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.net.URL self, java.lang.String regex, java.lang.String charset, Closure closure)

  Iterates through the input stream associated with this URL 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 URL are closed.
  throws:
    IOException if an IOException occurs.
  throws:
    java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
  Parameters:
    `self` - a URL to open and read
    `regex` - the delimiting regular expression
    `charset` - opens the file with a specified charset
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### splitEachLine

    public static java.lang.Object splitEachLine(java.net.URL self, java.util.regex.Pattern pattern, java.lang.String charset, Closure closure)

  Iterates through the input stream associated with this URL 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 URL are closed.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `self` - a URL to open and read
    `pattern` - the regular expression Pattern for the delimiter
    `charset` - opens the file with a specified charset
    `closure` - a closure
  Returns:
    the last value returned by the closure
  See Also:
    IOGroovyMethods.splitEachLine
  Since:
    1.6.8

### toURI

    public static java.net.URI toURI(java.lang.CharSequence self)

  Transforms a CharSequence representing a URI into a URI object.
  throws:
    java.net.URISyntaxException is thrown if the URI is not well formed.
  Parameters:
    `self` - the CharSequence representing a URI
  Returns:
    a URI
  Since:
    1.8.2

### toURI

    public static java.net.URI toURI(java.lang.String self)

### toURL

    public static java.net.URL toURL(java.lang.CharSequence self)

### toURL

    public static java.net.URL toURL(java.lang.String self)

### traverse

    public static void traverse(java.io.File self, java.util.Map options, Closure closure)

  Invokes `closure` for each descendant file in this directory tree. Sub-directories are recursively traversed as found. The traversal can be adapted by providing various options in the `options` Map according to the following keys:
  type
    A FileType enum to determine if normal files or directories or both are processed
  preDir
    A Closure run before each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
  preRoot
    A boolean indicating that the 'preDir' closure should be applied at the root level
  postDir
    A Closure run after each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
  postRoot
    A boolean indicating that the 'postDir' closure should be applied at the root level
  visitRoot
    A boolean indicating that the given closure should be applied for the root dir (not applicable if the 'type' is set to FileType.FILES)
  maxDepth
    The maximum number of directory levels when recursing (default is -1 which means infinite, set to 0 for no recursion)
  filter
    A filter to perform on traversed files/directories (using the DefaultGroovyMethods.isCase method). If set, only files/dirs which match are candidates for visiting.
  nameFilter
    A filter to perform on the name of traversed files/directories (using the DefaultGroovyMethods.isCase method). If set, only files/dirs which match are candidates for visiting. (Must not be set if 'filter' is set)
  excludeFilter
    A filter to perform on traversed files/directories (using the DefaultGroovyMethods.isCase method). If set, any candidates which match won't be visited.
  excludeNameFilter
    A filter to perform on the names of traversed files/directories (using the DefaultGroovyMethods.isCase method). If set, any candidates which match won't be visited. (Must not be set if 'excludeFilter' is set)
  sort
    A Closure which if set causes the files and subdirectories for each directory to be processed in sorted order. Note that even when processing only files, the order of visited subdirectories will be affected by this parameter.
  This example prints out file counts and size aggregates for groovy source files within a directory tree:

       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++ }

  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory or illegal filter combinations are supplied
  Parameters:
    `self` - a File
    `options` - a Map of options to alter the traversal behavior
    `closure` - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value which can be used to control subsequent processing
  See Also:
    DefaultGroovyMethods.sort
    FileVisitResult
    FileType
  Since:
    1.7.1

### traverse

    public static void traverse(java.io.File self, Closure closure)

  Invokes the closure for each descendant file in this directory tree. Sub-directories are recursively traversed in a depth-first fashion. Convenience method for traverse(java.io.File, java.util.Map, groovy.lang.Closure) when no options to alter the traversal behavior are required.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory
  Parameters:
    `self` - a File
    `closure` - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value which can be used to control subsequent processing
  See Also:
    traverse(java.io.File, java.util.Map, groovy.lang.Closure)
  Since:
    1.7.1

### traverse

    public static void traverse(java.io.File self, java.util.Map options)

  Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. Convenience method for traverse(java.io.File, java.util.Map, groovy.lang.Closure) allowing the 'visit' closure to be included in the options Map rather than as a parameter.
  throws:
    FileNotFoundException if the given directory does not exist
  throws:
    IllegalArgumentException if the provided File object does not represent a directory or illegal filter combinations are supplied
  Parameters:
    `self` - a File
    `options` - a Map of options to alter the traversal behavior
  See Also:
    traverse(java.io.File, java.util.Map, groovy.lang.Closure)
  Since:
    1.7.1

### withDataInputStream

    public static java.lang.Object withDataInputStream(java.io.File file, Closure closure)

### withDataOutputStream

    public static java.lang.Object withDataOutputStream(java.io.File file, Closure closure)

### withInputStream

    public static java.lang.Object withInputStream(java.io.File file, Closure closure)

### withInputStream

    public static java.lang.Object withInputStream(java.net.URL url, Closure closure)

### withObjectInputStream

    public static java.lang.Object withObjectInputStream(java.io.File file, Closure closure)

  Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `closure` - a closure
  Returns:
    the value returned by the closure
  See Also:
    IOGroovyMethods.withStream
  Since:
    1.5.2

### withObjectInputStream

    public static java.lang.Object withObjectInputStream(java.io.File file, java.lang.ClassLoader classLoader, Closure closure)

  Create 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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `classLoader` - the class loader to use when loading the class
    `closure` - a closure
  Returns:
    the value returned by the closure
  See Also:
    IOGroovyMethods.withStream
  Since:
    1.5.2

### withObjectOutputStream

    public static java.lang.Object withObjectOutputStream(java.io.File file, Closure closure)

  Create a new ObjectOutputStream for this file and then pass it to the closure. This method ensures the stream is closed after the closure returns.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `closure` - a closure
  Returns:
    the value returned by the closure
  See Also:
    IOGroovyMethods.withStream
  Since:
    1.5.0

### withOutputStream

    public static java.lang.Object withOutputStream(java.io.File file, Closure closure)

### withPrintWriter

    public static java.lang.Object withPrintWriter(java.io.File file, Closure closure)

### withPrintWriter

    public static java.lang.Object withPrintWriter(java.io.File file, java.lang.String charset, Closure closure)

### withReader

    public static java.lang.Object withReader(java.io.File file, Closure closure)

### withReader

    public static java.lang.Object withReader(java.io.File file, java.lang.String charset, Closure closure)

### withReader

    public static java.lang.Object withReader(java.net.URL url, Closure closure)

### withReader

    public static java.lang.Object withReader(java.net.URL url, java.lang.String charset, Closure closure)

### withWriter

    public static java.lang.Object withWriter(java.io.File file, Closure 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.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `closure` - a closure
  Returns:
    the value returned by the closure
  Since:
    1.5.2

### withWriter

    public static java.lang.Object withWriter(java.io.File file, java.lang.String charset, Closure closure)

### withWriterAppend

    public static java.lang.Object withWriterAppend(java.io.File file, java.lang.String charset, Closure closure)

### withWriterAppend

    public static java.lang.Object withWriterAppend(java.io.File file, Closure closure)

### write

    public static void write(java.io.File file, java.lang.String text)

  Write the text to the File.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to write to the File
  Since:
    1.0

### write

    public static void write(java.io.File file, java.lang.String text, java.lang.String charset)

  Write the text to the File, using the specified encoding.
  throws:
    IOException if an IOException occurs.
  Parameters:
    `file` - a File
    `text` - the text to write to the File
    `charset` - the charset used
  Since:
    1.0

Groovy Documentation