[英]Read CSV file and convert to Map using Groovy with Jenkins
I'm trying to convert csv file into Map.我正在尝试将 csv 文件转换为 Map。 I saw this code over here:我在这里看到了这段代码:
def convertResultFile(String file){
def testsResults = [:]
File csvFile = new File(file)
csvFile.eachLine { line ->
def parts = line.split(",")
testsResults.putAt(parts[0], parts[1])
}
}
My csv file is pretty simple (every line have only two words separated by ',')我的 csv 文件非常简单(每行只有两个用“,”分隔的词)
I got an exception when I'm trying to use eachLine
.当我尝试使用eachLine
时出现异常。
When I look into java.io.File
, eachLine
doesn't exist.当我查看java.io.File
, eachLine
不存在。
I am using Java 13.我正在使用 Java 13。
Don't reinvent the wheel, use the readCsv
utility function :不要重新发明轮子,使用readCsv
实用函数:
def convertResultFile(String filename) {
def testsResults = [:]
def csv_content = readCSV file: filename
for (def record : csv_content) {
testsResults[record[0]] = record[1]
}
println testsResults
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.