BufferedReader to skip first line

前端 未结 6 1655
余生分开走
余生分开走 2020-12-24 02:44

I am using the following bufferedreader to read the lines of a file,

BufferedReader reader = new BufferedReader(new FileReader(somepath));
whil         


        
6条回答
  •  长情又很酷
    2020-12-24 03:25

    You can create a counter that contains the value of the starting line:

    private final static START_LINE = 1;
    
    BufferedReader reader = new BufferedReader(new FileReader(somepath));
    int counter=START_LINE;
    
    while ((line1 = reader.readLine()) != null) {
      if(counter>START_LINE){
         //your code here
      }
      counter++;
    }
    

提交回复
热议问题