Skip first line while reading CSV file in Java

前端 未结 8 1601
别跟我提以往
别跟我提以往 2021-02-15 00:27

I am writing a parser code to read a .csv file and parse it to XML. This is the code I have and it works, except I would like it to skip the first line in the file. So I decided

8条回答
  •  甜味超标
    2021-02-15 00:49

    For skipping first line(which normally contains header of the columns) take a variable and increase this variable in while loop at first place, and continue;

    int lineNumber = 0;
    
    and then in while loop 
    
    while ((line = br.readLine()) != null) {
                            if(lineNumber == 0) {
                                lineNumber++;
                                continue;
                            }
                            lineNumber++;
    
                           //do waterver u have to do with the tokens in this line(second line)
    
                }
    

提交回复
热议问题