LoginSignup
0
0

More than 5 years have passed since last update.

Read file into String list (Java 8)

Last updated at Posted at 2016-07-28

設定

ファイル(text.txt)の中身

apple
bear
picnic
...

方法

方法1


List<String> words = java.nio.file.Files
                    .lines(Paths.get(getClass().getResource("/text.txt").toURI()))
                    .collect(Collectors.toList());

しかし、Jarファイル内のファイルが読み込めない(FileSystemNotFoundException)

方法2


List<String> words = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/text.txt")))
                    .lines().collect(Collectors.toList());
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0