Parse CSV file with Groovy
发布时间:2020-12-14 16:51:43 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/groovyclass 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 "${nam
#!/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 "" } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |