Put file "word" in the main Eclipse project directory. Don't worry about adding the path as per your 2nd try.
FileNotFoundException in server project in eclipse
Question
I work on a indexing project which create a file dynamically for all words start with same character and the name of that file is created based on first character of the words like:
file "a" contains apple, adapt,air,...
file "b" contains book, bad,bar,...
My project work correctly when I run through application but when I run it through server(tomcat) I got the following error for the given line of the code:
BufferedReader reader = new BufferedReader(new FileReader(getFileName(word)));
INFO: Server startup in 2785 ms
java.io.FileNotFoundException: C (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at DataLayer.FileRepository.getArrayListPosting(FileRepository.java:54)
I add the path to this word in the following code but I got the same error.
BufferedReader reader = new BufferedReader(new FileReader(getFileName("C:\\code\\"+word)));
what should I do, where should I put this file in eclipse? This is the image of my files in my project.
Solution
OTHER TIPS
java.io.FileNotFoundException: C (The system cannot find the file specified)
You probably forgot the :
in the path, and accidently made it C\\File
which is looking for a directory named C
, which doesnt exist.
The problem is that calling function which create the name of the project as argument of fileReader.The solution is :
String str= path+getFileName(word);
BufferedReader reader = new BufferedReader(new FileReader(str));
Any of these two solutions
1________ put the "word" file in the eclipse project directory. i.e the folder that contains the eclipse.exe application file
2_______ File file=new File("theFileFullPath"); According to your program, do it this way => File file= new File("C:\code\"+word)));
then::
BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath()));