Package: java.nio.file

## [Java] Interface Path

-     public interface Path

  GDK enhancements for Path.

  displayName:
    Path
  receiverFqcn:
    java.nio.file.Path

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `append(Object text)` Append the text at the end of the Path without writing a BOM.
    `` | `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(byte[] bytes)` Append bytes to the end of a Path.
    `` | `public void` | `append(InputStream stream)` Append binary data to the file.
    `` | `public void` | `append(Object text, boolean writeBom)` Append the text at the end of the Path.
    `` | `public void` | `append(Object text, String charset)` Append the text at the end of the Path 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 Path, using a specified encoding.
    `` | `public void` | `append(Writer writer, boolean writeBom)` Append the text supplied by the Writer 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 path to a `boolean` value.
    `<T>` | `public T` | `asType(Class<T> c)` Converts this Path to a Writable or delegates to default DefaultGroovyMethods.asType.
    `` | `public Path` | `asWritable()` Converts this Path to a Writable.
    `` | `public Path` | `asWritable(String encoding)` Allows a file to return a Writable implementation that can output itself to a Writer stream.
    `` | `public Path` | `createParentDirectories(FileAttribute<?> attrs)` Creates, if needed, any parent directories for the file associated with this Path.
    `` | `public boolean` | `deleteDir()` Deletes a directory with all contained files and subdirectories.
    `` | `public void` | `eachByte(Closure closure)` Traverse through each byte of this Path
    `` | `public void` | `eachByte(int bufferLen, Closure closure)` Traverse through the bytes of this Path, 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 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 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 path 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 boolean` | `exists(LinkOption options)` Tests whether the file at the path exists.
    `` | `public Writable` | `filterLine(Closure closure)` Filters the lines of a Path and creates a Writable in return to stream the filtered lines.
    `` | `public Writable` | `filterLine(String charset, Closure closure)` Filters the lines of a Path and creates a Writable in return to stream the filtered lines.
    `` | `public void` | `filterLine(Writer writer, Closure closure)` Filter the lines from this Path, 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 Path, and write them to the given writer based on the given closure predicate.
    `` | `public String` | `getBaseName()` Provide the path's name without an extension.
    `` | `public byte[]` | `getBytes()` Read the content of the Path and returns it as a byte[].
    `` | `public CompletableFuture<byte[]>` | `getBytesAsync()` Asynchronously read the content of the Path and return it as a byte array.
    `` | `public String` | `getExtension()` Provide the extension of this path.
    `` | `public String` | `getName()` Provide the name of the file or directory.
    `` | `public String` | `getText(String charset)` Read the content of the Path using the specified encoding and return it as a String.
    `` | `public String` | `getText()` Read the content of the Path and returns it as a String.
    `` | `public CompletableFuture<String>` | `getTextAsync()` Asynchronously read the content of the Path and return it as a String using the platform's default charset.
    `` | `public CompletableFuture<String>` | `getTextAsync(String charset)` Asynchronously read the content of the Path and return it as a String using the specified charset.
    `` | `public Path` | `leftShift(Object text)` Write the text to the Path.
    `` | `public Path` | `leftShift(byte[] bytes)` Write bytes to a Path.
    `` | `public Path` | `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 path using the given class loader.
    `` | `public ObjectOutputStream` | `newObjectOutputStream()` Create an object output stream for this path.
    `` | `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 without writing a BOM, writing data using the given 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 boolean` | `renameTo(String newPathName)` Renames a file.
    `` | `public boolean` | `renameTo(URI newPathName)` Renames a file.
    `` | `public void` | `setBytes(byte[] bytes)` Write the bytes from the byte array to the Path.
    `` | `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:
         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'
    `` | `public long` | `size()` Provide the standard Groovy `size()` method for `Path`.
    `<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, Object> 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, Object> 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.
    `<T>` | `public T` | `withInputStream(Closure<T> 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 path and then pass it to the closure.
    `<T>` | `public T` | `withOutputStream(Closure<T> 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` | `withWriter(String charset, boolean writeBom, 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(String charset, boolean writeBom, 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 Path without writing a BOM .
    `` | `public void` | `write(String text, boolean writeBom)` Write the text to the Path.
    `` | `public void` | `write(String text, String charset)` Write the text to the Path without writing a BOM, using the specified encoding.
    `` | `public void` | `write(String text, String charset, boolean writeBom)` Write the text to the Path, using the specified encoding.
    `` | `public CompletableFuture<Void>` | `writeAsync(String text)` Asynchronously write the String content to the Path using the platform's default charset.
    `` | `public CompletableFuture<Void>` | `writeAsync(String text, String charset)` Asynchronously write the String content to the Path using the specified charset.
    `` | `public CompletableFuture<Void>` | `writeBytesAsync(byte[] bytes)` Asynchronously write the byte array to the Path, creating the file if it doesn't exist and truncating it if it does.

- - ### Method Detail

    - #### public void append(Object text)

      Append the text at the end of the Path without writing a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to append at the end of the Path
      Since:
        2.3.0

    - #### public void append(Reader reader)

      Append the text supplied by the Writer at the end of the File without writing a BOM.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `reader` - the Reader supplying the text to append at the end of the File
      Since:
        2.3.0

    - #### public void append(Writer writer)

      Append the text supplied by the Writer at the end of the File without writing a BOM.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `writer` - the Writer supplying the text to append at the end of the File
      Since:
        2.3.0

    - #### public void append(byte[] bytes)

      Append bytes to the end of a Path. It will not be interpreted as text.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `bytes` - the byte array to append to the end of the Path
      Since:
        2.3.0

    - #### public void append(InputStream stream)

      Append binary data to the file. It will not be interpreted as text.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `stream` - stream to read data from.
      Since:
        2.3.0

    - #### public void append(Object text, boolean writeBom)

      Append the text at the end of the Path. 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to append at the end of the Path
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### public void append(Object text, String charset)

      Append the text at the end of the Path without writing a BOM, using a specified encoding.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to append at the end of the Path
        `charset` - the charset used
      Since:
        2.3.0

    - #### public void append(Object text, String charset, boolean writeBom)

      Append the text at the end of the Path, 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to append at the end of the Path
        `charset` - the charset used
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### public void append(Writer writer, boolean writeBom)

      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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `writer` - the Writer supplying the text to append at the end of the File
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### 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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `writer` - the Writer supplying the text to append at the end of the File
        `charset` - the charset used
      Since:
        2.3.0

    - #### 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. 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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `writer` - the Writer supplying the text to append at the end of the File
        `charset` - the charset used
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### public void append(Reader reader, boolean writeBom)

      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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `reader` - the Reader supplying the text to append at the end of the File
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### 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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `reader` - the Reader supplying the text to append at the end of the File
        `charset` - the charset used
      Since:
        2.3.0

    - #### 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. 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.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `reader` - the Reader supplying the text to append at the end of the File
        `charset` - the charset used
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### public boolean asBoolean()

      Coerce the path to a `boolean` value.

      By default this returns whether the file at the path exists. Set the system property `groovy.truth.file.exists.enabled` to `false` to restore the pre-Groovy-5 behavior where any non-`null` `Path` is truthy regardless of whether the underlying file exists.

      Returns:
        `true` if the file at the path exists, `false` otherwise
      See Also:
        Files#exists(Path, LinkOption...)
      Since:
        5.0.0

    - #### <T> public T asType(Class<T> c)

      Converts this Path to a Writable or delegates to default DefaultGroovyMethods.asType.

      Parameters:
        `c` - the desired class
      Returns:
        the converted object
      Since:
        2.3.0

    - #### public Path asWritable()

      Converts this Path to a Writable.

      Returns:
        a Path which wraps the input file and which implements Writable
      Since:
        2.3.0

    - #### public Path asWritable(String encoding)

      Allows a file to return a Writable implementation that can output itself to a Writer stream.

      Parameters:
        `encoding` - the encoding to be used when reading the file's contents
      Returns:
        Path which wraps the input file and which implements Writable
      Since:
        2.3.0

    - #### public Path createParentDirectories(FileAttribute<?> attrs)

      Creates, if needed, any parent directories for the file associated with this Path.

      throws:
        IOException if the parent directories couldn't be created
      Returns:
        itself

    - #### public boolean deleteDir()

      Deletes a directory with all contained files and subdirectories.

      The method returns

      - true, when deletion was successful
      - true, when it is called for a non existing directory
      - false, when it is called for a file which isn't a directory
      - false, when directory couldn't be deleted
      Returns:
        true if the file doesn't exist or deletion was successful
      Since:
        2.3.0

    - #### public void eachByte(Closure closure)

      Traverse through each byte of this Path

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      See Also:
        IOGroovyMethods.eachByte
      Since:
        2.3.0

    - #### public void eachByte(int bufferLen, Closure closure)

      Traverse through the bytes of this Path, bufferLen bytes at a time.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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.
      See Also:
        IOGroovyMethods.eachByte
      Since:
        2.3.0

    - #### public void eachDir(Closure closure)

      Invokes the closure for each subdirectory in this directory, ignoring regular files.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `closure` - a closure (the parameter is the Path for the subdirectory file)
      See Also:
        eachFile(Path, groovy.io.FileType, groovy.lang.Closure)
      Since:
        2.3.0

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

    - #### public void eachDirRecurse(Closure closure)

      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.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `closure` - a closure
      See Also:
        eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure)
      Since:
        2.3.0

    - #### public void eachFile(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:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `fileType` - if normal files or directories or both should be processed
        `closure` - the closure to invoke
      Since:
        2.3.0

    - #### public void eachFile(Closure closure)

      Invokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories are processed.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `closure` - a closure (the parameter is the Path for the 'child' file)
      See Also:
        eachFile(Path, groovy.io.FileType, groovy.lang.Closure)
      Since:
        2.3.0

    - #### 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 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/, { Path bak -> bak.delete() }

           // print out files > 4K in size from baseDir
           baseDir.eachFileMatch FILES, { new Path(baseDir, it).size() > 4096 }, { println "$it.name ${it.size()}" }

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `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:
        2.3.0

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

    - #### public void eachFileRecurse(FileType fileType, Closure 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. Whether the closure is called is determined by whether the file was a normal file or subdirectory and the value of fileType.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `fileType` - if normal files or directories or both should be processed
        `closure` - the closure to invoke on each file
      Since:
        2.3.0

    - #### public void eachFileRecurse(Closure closure)

      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.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `closure` - a Closure
      See Also:
        eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure)
      Since:
        2.3.0

    - #### <T> public T eachLine(Closure<T> closure)

      Iterates through this path 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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(Path, int, groovy.lang.Closure)
      Since:
        2.3.0

    - #### <T> public T eachLine(String charset, Closure<T> 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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(Path, String, int, groovy.lang.Closure)
      Since:
        2.3.0

    - #### <T> public T eachLine(int firstLine, Closure<T> 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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:
        2.3.0

    - #### <T> public T eachLine(String charset, int firstLine, Closure<T> 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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:
        2.3.0

    - #### public void eachObject(Closure closure)

      Iterates through the given file object by object.

      throws:
        java.io.IOException if an IOException occurs.
      throws:
        ClassNotFoundException if the class is not found.
      Parameters:
        `closure` - a closure
      See Also:
        IOGroovyMethods.eachObject
      Since:
        2.3.0

    - #### public boolean exists(LinkOption options)

      Tests whether the file at the path exists.

      Parameters:
        `options` - options indicating how symbolic links are handled .
      Returns:
        `true` if the file exists; `false` if the file does not exist or its existence cannot be determined
      See Also:
        Files#exists(Path, LinkOption...)
      Since:
        5.0.0

    - #### public Writable filterLine(Closure closure)

      Filters the lines of a Path and creates a Writable in return to stream the filtered lines.

      throws:
        java.io.IOException if `self` is not readable
      Parameters:
        `closure` - a closure which returns a boolean indicating to filter the line or not
      Returns:
        a Writable closure
      See Also:
        IOGroovyMethods.filterLine
      Since:
        2.3.0

    - #### public Writable filterLine(String charset, Closure closure)

      Filters the lines of a Path and creates a Writable in return to stream the filtered lines.

      throws:
        java.io.IOException if an IOException occurs
      Parameters:
        `charset` - opens the file with a specified charset
        `closure` - a closure which returns a boolean indicating to filter the line or not
      Returns:
        a Writable closure
      See Also:
        IOGroovyMethods.filterLine
      Since:
        2.3.0

    - #### public void filterLine(Writer writer, Closure closure)

      Filter the lines from this Path, and write them to the given writer based on the given closure predicate.

      throws:
        java.io.IOException if `self` is not readable
      Parameters:
        `writer` - a writer destination to write filtered lines to
        `closure` - a closure which takes each line as a parameter and returns `true` if the line should be written to this writer.
      See Also:
        IOGroovyMethods.filterLine
      Since:
        2.3.0

    - #### public void filterLine(Writer writer, String charset, Closure closure)

      Filter the lines from this Path, and write them to the given writer based on the given closure predicate.

      throws:
        java.io.IOException if an IO error occurs
      Parameters:
        `writer` - a writer destination to write filtered lines to
        `charset` - opens the file with a specified charset
        `closure` - a closure which takes each line as a parameter and returns `true` if the line should be written to this writer.
      See Also:
        IOGroovyMethods.filterLine
      Since:
        2.3.0

    - #### public String getBaseName()

      Provide the path's name without an extension.

      Returns:
        the name of this file or directory without an extension, or an empty string if this path has zero path elements.
      Since:
        5.0.0

    - #### public byte[] getBytes()

      Read the content of the Path and returns it as a byte[].

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a String containing the content of the file
      Since:
        2.3.0

    - #### public CompletableFuture<byte[]> getBytesAsync()

      Asynchronously read the content of the Path and return it as a byte array.

      Uses AsynchronousFileChannel internally. The entire file content is read into a byte array.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.bytes = [72, 105] as byte[]
           assert path.bytesAsync.get() == [72, 105] as byte[]
           Files.delete(path)

      Returns:
        a CompletableFuture that completes with the file content as a byte array
      Since:
        6.0.0

    - #### public String getExtension()

      Provide the extension of this path.

      Returns:
        the extension of this path (not including the dot), or an empty string if it doesn't have one.
      Since:
        5.0.0

    - #### public String getName()

      Provide the name of the file or directory.

      Returns:
        the name of the file or directory denoted by this path as a string, or an empty string if this path has zero path elements.
      Since:
        5.0.0

    - #### public String getText(String charset)

      Read the content of the Path using the specified encoding and return it as a String.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used to read the content of the file
      Returns:
        a String containing the content of the file
      Since:
        2.3.0

    - #### public String getText()

      Read the content of the Path and returns it as a String.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a String containing the content of the file
      Since:
        2.3.0

    - #### public CompletableFuture<String> getTextAsync()

      Asynchronously read the content of the Path and return it as a String using the platform's default charset.

      Uses AsynchronousFileChannel internally, making the I/O non-blocking. The returned CompletableFuture completes when the entire file has been read.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.text = 'Hello async'
           assert path.textAsync.get() == 'Hello async'
           Files.delete(path)

      Returns:
        a CompletableFuture that completes with the file content as a String
      Since:
        6.0.0

    - #### public CompletableFuture<String> getTextAsync(String charset)

      Asynchronously read the content of the Path and return it as a String using the specified charset.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.text = 'Hello async'
           assert path.getTextAsync('UTF-8').get() == 'Hello async'
           Files.delete(path)

      Parameters:
        `charset` - the charset used to decode the file content
      Returns:
        a CompletableFuture that completes with the file content as a String
      Since:
        6.0.0

    - #### public Path leftShift(Object text)

      Write the text to the Path.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
      Returns:
        the original file
      Since:
        2.3.0

    - #### public Path leftShift(byte[] bytes)

      Write bytes to a Path.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `bytes` - the byte array to append to the end of the Path
      Returns:
        the original file
      Since:
        2.3.0

    - #### public Path leftShift(InputStream data)

      Append binary data to the file. See Path.append

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `data` - an InputStream of data to write to the file
      Returns:
        the file
      Since:
        2.3.0

    - #### public DataInputStream newDataInputStream()

      Create a data input stream for this file

      throws:
        java.io.FileNotFoundException if the file is not found.
      Returns:
        a DataInputStream of the file
      Since:
        2.3.0

    - #### public DataOutputStream newDataOutputStream()

      Creates a new data output stream for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        the created DataOutputStream
      Since:
        2.3.0

    - #### public BufferedInputStream newInputStream()

      Creates a buffered input stream for this file.

      throws:
        java.io.FileNotFoundException if the file is not found.
      Returns:
        a BufferedInputStream of the file
      Since:
        2.3.0

    - #### public ObjectInputStream newObjectInputStream()

      Create an object input stream for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        an object input stream
      Since:
        2.3.0

    - #### public ObjectInputStream newObjectInputStream(ClassLoader classLoader)

      Create an object input stream for this path using the given class loader.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `classLoader` - the class loader to use when loading the class
      Returns:
        an object input stream
      Since:
        2.3.0

    - #### public ObjectOutputStream newObjectOutputStream()

      Create an object output stream for this path.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        an object output stream
      Since:
        2.3.0

    - #### public BufferedOutputStream newOutputStream()

      Create a buffered output stream for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        the created OutputStream
      Since:
        2.3.0

    - #### public PrintWriter newPrintWriter()

      Create a new PrintWriter for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        the created PrintWriter
      Since:
        2.3.0

    - #### public PrintWriter newPrintWriter(String charset)

      Create a new PrintWriter for this file, using specified charset.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset
      Returns:
        a PrintWriter
      Since:
        2.3.0

    - #### public BufferedReader newReader()

      Create a buffered reader for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a BufferedReader
      Since:
        2.3.0

    - #### public BufferedReader newReader(String charset)

      Create a buffered reader for this file, using the specified charset as the encoding.

      throws:
        java.io.FileNotFoundException if the Path was not found
      throws:
        java.io.UnsupportedEncodingException if the encoding specified is not supported
      Parameters:
        `charset` - the charset for this Path
      Returns:
        a BufferedReader
      Since:
        2.3.0

    - #### public BufferedWriter newWriter()

      Create a buffered writer for this file.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a BufferedWriter
      Since:
        2.3.0

    - #### public BufferedWriter newWriter(boolean append)

      Creates a buffered writer for this file, optionally appending to the existing file content.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `append` - true if data should be appended to the file
      Returns:
        a BufferedWriter
      Since:
        2.3.0

    - #### public BufferedWriter newWriter(String charset, boolean append)

      Helper method to create a buffered writer for a file without writing a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the name of the encoding used to write in this file
        `append` - true if in append mode
      Returns:
        a BufferedWriter
      Since:
        2.3.0

    - #### public BufferedWriter newWriter(String charset, boolean append, boolean writeBom)

      Helper 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the name of the encoding used to write in this file
        `append` - true if in append mode
        `writeBom` - whether to write a BOM
      Returns:
        a BufferedWriter
      Since:
        2.5.0

    - #### public BufferedWriter newWriter(String charset)

      Creates a buffered writer for this file without writing a BOM, writing data using the given encoding.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the name of the encoding used to write in this file
      Returns:
        a BufferedWriter
      Since:
        2.3.0

    - #### public byte[] readBytes()

      Reads the content of the file into a byte array.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a byte array with the contents of the file.
      Since:
        2.3.0

    - #### public List<String> readLines()

      Reads the file into a list of Strings, with one item for each line.

      throws:
        java.io.IOException if an IOException occurs.
      Returns:
        a List of lines
      See Also:
        IOGroovyMethods.readLines
      Since:
        2.3.0

    - #### public List<String> readLines(String charset)

      Reads the file into a list of Strings, with one item for each line.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - opens the file with a specified charset
      Returns:
        a List of lines
      See Also:
        IOGroovyMethods.readLines
      Since:
        2.3.0

    - #### public boolean renameTo(String newPathName)

      Renames a file.

      Parameters:
        `newPathName` - The new pathname for the named file
      Returns:
        `true` if and only if the renaming succeeded; `false` otherwise
      Since:
        2.3.0

    - #### public boolean renameTo(URI newPathName)

      Renames a file.

      Parameters:
        `newPathName` - The new target path specified as a URI object
      Returns:
        `true` if and only if the renaming succeeded; `false` otherwise
      Since:
        2.3.0

    - #### public void setBytes(byte[] bytes)

      Write the bytes from the byte array to the Path.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `bytes` - the byte[] to write to the file
      Since:
        2.3.0

    - #### public void setText(String text)

      Synonym for write(text) allowing file.text = 'foo'.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
      See Also:
        write(Path, String)
      Since:
        2.3.0

    - #### public void setText(String text, 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - The charset used when writing to the file
        `text` - The text to write to the Path
      See Also:
        write(Path, String, String)
      Since:
        2.3.0

    - #### public long size()

      Provide the standard Groovy `size()` method for `Path`.

      Returns:
        the file's size (length)
      Since:
        2.3.0

    - #### <T> public T splitEachLine(String regex, Closure<T> 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:
        java.io.IOException if an IOException occurs.
      throws:
        java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
      Parameters:
        `regex` - the delimiting regular expression
        `closure` - a closure
      Returns:
        the last value returned by the closure
      See Also:
        IOGroovyMethods.splitEachLine
      Since:
        2.3.0

    - #### <T> public T splitEachLine(Pattern pattern, Closure<T> 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `pattern` - the regular expression Pattern for the delimiter
        `closure` - a closure
      Returns:
        the last value returned by the closure
      See Also:
        IOGroovyMethods.splitEachLine
      Since:
        2.3.0

    - #### <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. 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:
        java.io.IOException if an IOException occurs.
      throws:
        java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid
      Parameters:
        `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:
        2.3.0

    - #### <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. 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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:
        2.3.0

    - #### public void traverse(Map<String, Object> options, Closure 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:

      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(Object, Object)#isCase(Object, Object) 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(Object, Object)#isCase(Object, Object) 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(Object, Object)#isCase(Object, Object) 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(Object, Object)#isCase(Object, Object) 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:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory or illegal filter combinations are supplied
      Parameters:
        `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(java.lang.Iterable, groovy.lang.Closure)
        FileVisitResult
        FileType
      Since:
        2.3.0

    - #### public void traverse(Closure closure)

      Processes each descendant file in this directory and any subdirectories. Convenience method for Path.traverse when no options to alter the traversal behavior are required.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory
      Parameters:
        `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(Path, java.util.Map, groovy.lang.Closure)
      Since:
        2.3.0

    - #### public void traverse(Map<String, Object> options)

      Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. Convenience method for Path.traverse allowing the 'visit' closure to be included in the options Map rather than as a parameter.

      throws:
        java.io.FileNotFoundException if the given directory does not exist
      throws:
        IllegalArgumentException if the provided Path object does not represent a directory or illegal filter combinations are supplied
      Parameters:
        `options` - a Map of options to alter the traversal behavior
      See Also:
        traverse(Path, java.util.Map, groovy.lang.Closure)
      Since:
        2.3.0

    - #### <T> public T withDataInputStream(Closure<T> closure)

      Create a new DataInputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods.withStream
      Since:
        2.3.0

    - #### <T> public T withDataOutputStream(Closure<T> closure)

      Create a new DataOutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods.withStream
      Since:
        2.3.0

    - #### <T> public T withInputStream(Closure<T> closure)

      Create a new InputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods.withStream
      Since:
        2.3.0

    - #### <T> public T withObjectInputStream(Closure<T> 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:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods.withStream
      Since:
        2.3.0

    - #### <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. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `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:
        2.3.0

    - #### <T> public T withObjectOutputStream(Closure<T> closure)

      Create a new ObjectOutputStream for this path and then pass it to the closure. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods#withStream(java.io.OutputStream, groovy.lang.Closure)
      Since:
        2.3.0

    - #### <T> public T withOutputStream(Closure<T> closure)

      Creates a new OutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      See Also:
        IOGroovyMethods.withStream
      Since:
        2.3.0

    - #### <T> public T withPrintWriter(Closure<T> closure)

      Create 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - the closure to invoke with the PrintWriter
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <T> public T withPrintWriter(String charset, Closure<T> closure)

      Create a new PrintWriter with a specified charset for this file. The writer is passed to the closure, and will be closed before this method returns.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset
        `closure` - the closure to invoke with the PrintWriter
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <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. The writer will use the given charset encoding, but will not write a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset for this input stream
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <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. The writer will not write a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <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. The writer will use the given charset encoding, but will not write a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <T> public T withWriter(String charset, boolean writeBom, 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. The writer will use the given charset 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 stream when the writer is created.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used
        `writeBom` - whether to write the BOM
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.5.0

    - #### <T> public T withWriterAppend(String charset, Closure<T> closure)

      Create a new BufferedWriter which will append to this file. The writer is passed to the closure and will be closed before this method returns. The writer will use the given charset encoding, but will not write a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### <T> public T withWriterAppend(String charset, boolean writeBom, Closure<T> closure)

      Create a new BufferedWriter which will append to this file. The writer is passed to the closure and will be closed before this method returns. The writer will use the given charset 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 stream when the writer is created.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `charset` - the charset used
        `writeBom` - whether to write the BOM
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.5.0

    - #### <T> public T withWriterAppend(Closure<T> closure)

      Create a new BufferedWriter for this file in append mode. The writer is passed to the closure and is closed after the closure returns. The writer will not write a BOM.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `closure` - a closure
      Returns:
        the value returned by the closure
      Since:
        2.3.0

    - #### public void write(String text)

      Write the text to the Path without writing a BOM .

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
      Since:
        2.3.0

    - #### public void write(String text, boolean writeBom)

      Write the text to the Path. 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
        `writeBom` - whether to write the BOM
      Since:
        2.5.0

    - #### public void write(String text, String charset)

      Write the text to the Path without writing a BOM, using the specified encoding.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
        `charset` - the charset used
      Since:
        2.3.0

    - #### public void write(String text, String charset, boolean writeBom)

      Write the text to the Path, 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.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `text` - the text to write to the Path
        `charset` - the charset used
        `writeBom` - whether to write a BOM
      Since:
        2.5.0

    - #### public CompletableFuture<Void> writeAsync(String text)

      Asynchronously write the String content to the Path using the platform's default charset.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.writeAsync('Hello async').get()
           assert path.text == 'Hello async'
           Files.delete(path)

      Parameters:
        `text` - the text to write
      Returns:
        a CompletableFuture that completes when the write is finished
      Since:
        6.0.0

    - #### public CompletableFuture<Void> writeAsync(String text, String charset)

      Asynchronously write the String content to the Path using the specified charset.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.writeAsync('Hello async', 'UTF-8').get()
           assert path.text == 'Hello async'
           Files.delete(path)

      Parameters:
        `text` - the text to write
        `charset` - the charset used to encode the text
      Returns:
        a CompletableFuture that completes when the write is finished
      Since:
        6.0.0

    - #### public CompletableFuture<Void> writeBytesAsync(byte[] bytes)

      Asynchronously write the byte array to the Path, creating the file if it doesn't exist and truncating it if it does.

           import java.nio.file.Files
           def path = Files.createTempFile('test', '.txt')
           path.writeBytesAsync([72, 105] as byte[]).get()
           assert path.bytes == [72, 105] as byte[]
           Files.delete(path)

      Parameters:
        `bytes` - the byte array to write
      Returns:
        a CompletableFuture that completes when the write is finished
      Since:
        6.0.0