Read a text file line by line in Groovy

Groovy
import java.nio.file.Files
import java.nio.file.Path

Path file = Path.of('events.log')
int kept = 0
long chars = 0L
Files.newBufferedReader(file).withCloseable { reader ->
    reader.eachLine { String line ->
        String trimmed = line.trim()
        if (trimmed && !trimmed.startsWith('#')) {
            kept++
            chars += trimmed.length()
        }
    }
}
println "kept=$kept chars=$chars"