In my project i want to read data from several textfiles, therefore I have organized them into folders likte following:
- textfiles
- folder1
- subfolder1
- file.txt
- subfolder2
- subfolder1
- folder2
- subfolder3
- folder1
My problem is that I don´t know where to put my folder or how to referance my textfiles. I have read Where to put a textfile I want to use in eclipse? and have a setup looking like this:
Folder location:
workspace/porjectX/src/textfiles
Code:
FileInputStream fis= new FileInputStream("/textfiles/folder1/subfolder1/file.txt");
The result i get is a “FileNotFoundException”…
I have checked spelling, everything is lowercase and with no spaces.
Any thoughts?
Thanks for any help!
First you have to make sure the folder testfiles is on your build path (Project->Properties->Java Build Path).
Then you can get the inputstream for the file the following way:
See also: getResourceAsStream() vs FileInputStream