How to open a txt file and read numbers in Java

后端 未结 6 1051
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 18:17

How can I open a .txt file and read numbers separated by enters or spaces into an array list?

6条回答
  •  囚心锁ツ
    2020-11-27 18:58

    Good news in Java 8 we can do it in one line:

    List ints = Files.lines(Paths.get(fileName))
                              .map(Integer::parseInt)
                              .collect(Collectors.toList());
    

提交回复
热议问题