Java : Read last n lines of a HUGE file

后端 未结 11 1783
温柔的废话
温柔的废话 2020-11-27 04:59

I want to read the last n lines of a very big file without reading the whole file into any buffer/memory area using Java.

I looked around the JDK APIs and Apache Com

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 05:23

    The ReversedLinesFileReader can be found in the Apache Commons IO java library.

        int n_lines = 1000;
        ReversedLinesFileReader object = new ReversedLinesFileReader(new File(path));
        String result="";
        for(int i=0;i

提交回复
热议问题