java8/Java8InAction

FileNotFoundException when running ExecuteAround main method in chap3 package

RickyGo opened this issue · 2 comments

I think that replace "lambdasinaction/chap3/data.txt" with ExecuteAround.class.getResource("/lambdasinaction/chap3/data.txt").getPath() should solve the problem.

Swap out new FileReader("lambdasinaction/chap3/data.txt") with new InputStreamReader(ClassLoader.getSystemResourceAsStream("lambdasinaction/chap3/data.txt")) and it works correctly.

And this worked for me too.

Files.newBufferedReader(Paths.get(ExecuteAround.class.getResource("/lambdasinaction/chap3/data.txt").getPath()))

You can swap for :
try (BufferedReader br = new BufferedReader(new FileReader("src/main/resources/lambdasinaction/chap3/data.txt"))) {
with absolute path.