BufferedReader to skip first line

前端 未结 6 1643
余生分开走
余生分开走 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:05

    File file = new File("path to file");
    FileInputStream fis = new FileInputStream(file);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String line = null;
    int count = 0;
    while((line = br.readLine()) != null) { // read through file line by line
        if(count != 0) { // count == 0 means the first line
            System.out.println("That's not the first line");
        }
        count++; // count increments as you read lines
    }
    br.close(); // do not forget to close the resources
    

提交回复
热议问题