我有以下代码从 csv 文件中读取数据,它遍历行,但我不知道如何遍历特定列(例如该行的前 2 列)以找到数据。有什么建议么?
String file = "pathToCsvFile";
BufferedReader reader = null;
String line = "";
try {
reader = new BufferedReader(new FileReader(file));
while((line = reader.readLine()) != null) {
String[] row = line.split(",");
for(String index:row) {
//HERE I NEED THE DATA OF THE FIRST 2 COLUMNS OF THE ROW
}
}
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
reader.close();
} catch(IOException e) {
e.printStackTrace();
}
}