推荐一个工具包hutool-all,非常好用

<dependency>
	<groupId>cn.hutool</groupId>
	<artifactId>hutool-all</artifactId>
	<version>4.1.2</version>
</dependency>

 读取txt文本

private List<String> termOpenList() throws IOException {
        List<String> list = new ArrayList<>();
        String fileName = "2.sql";
        String path = prefixPath + fileName;
        FileReader fileReader = new FileReader(path);
        BufferedReader reader = fileReader.getReader();
        String text = null;
        while ((text = reader.readLine()) != null) {
            list.add(text);
        }
        reader.close();
        return list;
    }

读取csv

public void readerCsv() {
        try {
            List<String> openList = termOpenList();
            String fileCsvName = "20200810_065440_00943_4zcsc.csv";
            String path = prefixPath + fileCsvName;
            File file = new File(path);
            CsvReader csvReader = new CsvReader();
            CsvData csvData = csvReader.read(file);
            List<CsvRow> dataRows = csvData.getRows();
            for (int i = 1; i < dataRows.size(); i++) {
                CsvRow csvRow = dataRows.get(i);
                String tid = csvRow.get(0);               
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页