0
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?
}

whileループ内での目的について言及しました。

4

1 に答える 1

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?
}
于 2013-01-07T10:20:22.317 に答える