#!/usr/bin/groovy
class CsvParser {
static void parse(String filePath, Closure closure) {
File file = new File(filePath)
file.eachLine() {line ->
def fields = line.split(";")
closure(fields)
}
}
static void usage(String name) {
println "${name} <csv file>"
}
static void main(String[] args) {
if (args.size() < 1) {
usage(CsvParser.getProtectionDomain().getCodeSource().getLocation().getPath())
return
}
parse(args[0]){fields ->
def i =0
for (field in fields) {
print "[${i}]" + field + " "
i++
}
println ""
}
}
}
Parse CSV file with Groovy
最新推荐文章于 2024-08-09 07:59:39 发布