我想跳过第一行的第一列并将每个元素与字符串进行比较。 Java代码
String csvFileToRead = "C:\\Users\\Dell\\Downloads\\Tasks.csv";
BufferedReader br = null;
String[] Task = null;
String line;
String splitBy = ",";
br = new BufferedReader(new FileReader(csvFileToRead));
System.out.println("Excel data for Subejct: ");
while ((line = br.readLine()) != null) {
Task = line.split(splitBy);
System.out.println(Task[0]);
}
答案 0 :(得分:0)
要跳过第一行,只需执行br.readLine()
。要跳过第一列,请在1
而不是0
处迭代单元格。
见这个例子:
br.readLine(); //skips the first row
while ((line = br.readLine()) != null) {
String[] cells = line.split(splitBy);
//starting from 1 essentially skips the first column
for (int col = 1; col < cells.length; col++) {
if (cells[col].equals(someString)) {
//do something
}
}
}
答案 1 :(得分:0)
为循环添加一个br.readLine()
outise,用于行跳转。
打印所有cols但第一个cols:
for(int i = 1; i < Task.lenght ; ++i){
System.out.println(Task[i]);
}