Reputation: 45
I have created a new folder in "scr" with the name "resources". There I have put my file "Test.txt". Now I would like to read in this file with a BufferedReader. This is my current code:
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("/resources/Test.txt").getFile());
in = new BufferedReader(new FileReader(file));
But it doesn't work! The file is not found. Why?
Upvotes: 0
Views: 5210
Reputation: 435
Make sure you have added the resources folder to your Build Path, and change
classLoader.getResource("/resources/Test.txt").getFile()
to
classLoader.getResource("Test.txt").getFile()
Upvotes: 1