1. 程式人生 > >springboot 讀取resources文字檔案

springboot 讀取resources文字檔案

public static List<String> readCsv(String path) {
    List<String> list = new ArrayList<>();

    InputStream ins = null;
    BufferedReader reader = null;
    try {
        Resource resource = new ClassPathResource(path);
        ins = resource.getInputStream();

        reader = new 
BufferedReader(new InputStreamReader(ins, "UTF-8")); String line = ""; while ((line = reader.readLine()) != null) { list.add(line); } } catch (Exception e) { } finally { try { if (reader != null) { reader.close(); reader = null
; } if (ins != null) { ins.close(); ins = null; } } catch (IOException e) { } } return list; }