如何把resources文件夹下txt文件内容读取出来

 String path = this.getClass().getClassLoader().getResource("contno.txt").getPath();
        System.out.println(path);
        List list=new ArrayList<>();
        try {
            FileReader reader = new FileReader(path);
            BufferedReader br = new BufferedReader(reader);
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                list.add(line.trim());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(list);



   List list=new ArrayList<>();
        Resource rource=resourceLoader.getResource("classpath:contno.txt");
        System.out.println(rource.getFile().getPath());
        try {
            FileReader reader = new FileReader(rource.getFile().getPath());
            BufferedReader br = new BufferedReader(reader);
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                list.add(line.trim());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(list);
contno.txt 文件格式如下
11
22
33
44

你可能感兴趣的:(如何把resources文件夹下txt文件内容读取出来)