【发布时间】:2014-04-14 10:52:58
【问题描述】:
我正在尝试解析通过在目录上递归获得的 CSV 文件列表。下面的代码只打印一行,然后存在 Stream Closed Error :
def stageDir = new File(STAGE_DIR), listOfFiles = [], filesData = []
// Get the list of files
stageDir.eachFileRecurse(FileType.FILES) { file ->
listOfFiles << file
}
// Start parsing each CSV file in the list
listOfFiles.each { file ->
def csvData = file.withReader {
new CsvParser().parse( it , separator: CSV_SEPARATOR )
}
// Here i put the returned csvData (of type CsvIterator) in the filesData
filesData.add(csvData)
}
// I checked filesData and it's not empty, so i iterate over it.
// HERE I GET : Stream Closed error
// I'm just trying to test by printing the first line of myIt
// (but is there a more efficient way to iterate over CsvIterator ?)
for (myIt in filesData) {
println myIt[0].ID + " " + myIt[0].NAME
}
有没有更好的方法来使用 CsvParser 处理多个文件并避免 Stream Closed 错误?
【问题讨论】:
标签: csv groovy ioexception