Store text file content line by line into array

后端 未结 11 1385
梦毁少年i
梦毁少年i 2020-12-05 12:09

all,I\'m now facing the problem of no idea on storing the content in text file into the array. The situation is like, text file content:

abc1
xyz2
rxy3
         


        
11条回答
  •  没有蜡笔的小新
    2020-12-05 12:42

    You can use this code. This works very fast!

    public String[] loadFileToArray(String fileName) throws IOException {
        String s = new String(Files.readAllBytes(Paths.get(fileName)));
        return Arrays.stream(s.split("\n")).toArray(String[]::new);
    }
    

提交回复
热议问题