java8 / Java8InAction

MIT License
3.19k stars 2.26k forks source link

FileNotFoundException when running ExecuteAround main method in chap3 package #5

Open RickyGo opened 9 years ago

RickyGo commented 9 years ago

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

ghost commented 9 years ago

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()))

felipealvesgnu commented 7 years ago

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