springboot 讀取resources文字檔案
阿新 • • 發佈:2019-02-14
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 = newBufferedReader(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; }