读取文件内容返回List<String>类型

文件内容格式:

string1

string2

String 3

……

很简单,两句话

String content = new String(Files.readAllBytes(Paths.get(".\src\main\resources\content")));
List<String> sequences = Arrays.asList(content.split("
"));

还有一个办法,相对啰嗦一点:

  String path= ".\src\main\resources\content";

  BufferedReader contentbr = new BufferedReader(new FileReader(path));
  String line = "";

  List<String> contentString= new ArrayList<>();
  while ((line = contentbr.readLine()) != null) {
   contentString.add(line);

  }

  return contentString;

原文地址:https://www.cnblogs.com/ilazysoft/p/6266956.html