Java Reference
In-Depth Information
void writeAccountsToFile() {
accountsFile.withWriter { w ->
accounts.each { id, account ->
w.println ("$id,$account.balance")
}
}
dirty = true
}
The withWriter method is from the Groovy JDK and is added to the java.io.File
class. It provides an output writer wrapped around the file that closes automatically when
the closure argument completes. The closure writes the ID and balance of each account to
a single line in the file, separated by a comma. Because this method changes the file, it sets
the dirty flag to true so that the class knows the cache needs to be refreshed.
With those methods in place, the next listing shows the complete DAO implementation.
Search WWH ::




Custom Search