import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class PagingReadFile {
    
    public static int sortCount = 0;
    
    public final static int PAGING_COUNT = 100;
    
    public static void pagingReadFileData(){
        int totalCount = getTotalCount();
        
        int count = 0;
        List<String> stringList = new ArrayList();
        String temp = "";
        try (BufferedReader reader =
                     new BufferedReader(
                             new InputStreamReader(
                                     new FileInputStream(new File("D:\\Users\\Desktop\\paging.txt"))
                                     , "UTF-8"))) {
            while ((temp = reader.readLine()) != null) {
                count++;
                stringList.add(temp);
                
                if (stringList.size() == PAGING_COUNT || count == totalCount) {
                    printFileContent(stringList);
                    
                    stringList.clear();
                }
            }
        } catch (Exception e) {
        }
    }
    
    public static int getTotalCount() {
        int count = 0;
        try (BufferedReader reader =
                     new BufferedReader(
                             new InputStreamReader(
                                     new FileInputStream(new File("D:\\Users\\Desktop\\paging.txt"))
                                     , "UTF-8"))) {
            while (reader.readLine() != null) {
                count ++;
            }
        } catch (Exception e) {
        }
        return count;
    }
    
    public static void printFileContent (List<String> stringList) {
        System.out.println("第" + ++sortCount + "页数据:" + stringList);
    }
    
    public static void writeDateToFile () {
        try (BufferedWriter writer =
                     new BufferedWriter(
                             new OutputStreamWriter(
                                     new FileOutputStream(new File("D:\\Users\\Desktop\\paging.txt"))
                                     , "UTF-8"))) {
            for (int i = 1; i <= 2022; i++) {
                writer.append(i + "\r\n");
            }
        } catch (Exception e) {
        }
    }
}