【发布时间】:2013-02-11 20:17:24
【问题描述】:
如何从使用 OpenCSV 库解析的文件中获取行号,其中出现特定条件?我希望在他们的 CSV 文件中用行号警告用户,只要该行上检测到潜在的错误值。
这是我将文件解析为字符串数组的一段代码:
try
{
CSVReader reader = new CSVReader(new FileReader(filePath), ',');
// Reads the complete file into list of tokens.
List<String[]> rowsAsTokens = null;
try
{
rowsAsTokens = reader.readAll();
}
for(String[] row: rowsAsTokens)
{
//Check for conditions within CSV file
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
【问题讨论】:
-
你知道如何将 int linecounter 加一吗?
标签: java parsing csv file-io conditional-statements