String csvFilename = "C:\\ClothingItem.csv";
CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
String[] row = null;
while ((row = csvReader.readNext()) != null ) {
// Here my objective is to check if row[0] contains some
// string"abc" then
// I want to add the next 15 lines from csv file to a list.
// Then again check the same condition after those lines means
// from the 16th line and than add again to the list.
// How could I approach?
}
我在循环中提到了我的目标。
答案 0 :(得分:0)
int counter=0;
while ((row = csvReader.readNext()) != null ) {
//Here my objective is to check if row[0] contains some string"abc" then
if(counter==0 && row.contains("abc")) {
counter=15; //Might be off by one depending upon the condition you have, would you include "abc" line or not?
}
counter--;
if(counter>0) {
//Add this line to a List.
}
// I want to add the next 15 lines from csv file to a list. Then again check the same condition after those lines means from the 16th line and than add again to the list.How could I approach?
}