Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reverted from v. 10 - my code is buggy

...

Code Block
java
java
// Create a ref for closure
def delClos

// Define closure
delClos = { println "Dir ${it.canonicalPath}";
            it.eachDir( delClos );
            it.eachFile {
                println "File ${it.canonicalPath}";
                it.delete()
            }
		it.delete()
}

// Apply closure
delClos( new File("D:/tmp/test") )

Contact/append one file into another

Implement cat file1 file2 > file3

the Groovy Way

 

Code Block
// Appends the src file into the target
def appendFile(File src, File target) {
    target.withWriter{ writer ->
        src.eachLine { writer.println(it) }
    }
}