Simple FileNotFoundException
Hi,
Doing the most simplist input from a text file.
try
{
FileReader fin = new FileReader("menu.txt");
BufferedReader din = new BufferedReader(fin);
String line = "";
while ((line = din.readLine()) != null)
{
StringTokenizer st = new java.util.StringTokenizer(line," ");
for (int i = 0; i<dayMenu.length; i++)
{
dayMenu[i] = st.nextToken().trim();
}
}
din.close();
}
but im getting FileNotFoundException. The .txt file is in the projects directory (if i write a little output to file it goes to the same place). I just dont know why this would fail. The txt file is not read-only.
Thankyou for any help
[942 byte] By [
admonrain] at [2007-11-11 8:30:00]

# 1 Re: Simple FileNotFoundException
FileNotFoundException is file not found, so you can try using the path FileReader(".\menu.txt");. or try moving the text file to another of your folders in the project. usually it should be the main folder. if you use eclipse, it should be the folder named src (eg the same folder as the root of sources, not of the project)
# 2 Re: Simple FileNotFoundException
also, you could find out where the .class files are going to after you compile, and throw the text file in there
ftr at 2007-11-11 22:36:16 >

# 3 Re: Simple FileNotFoundException
FileNotFoundException is file not found, so you can try using the path FileReader(".\menu.txt");. or try moving the text file to another of your folders in the project. usually it should be the main folder. if you use eclipse, it should be the folder named src (eg the same folder as the root of sources, not of the project)
I get an illegal space character on that so I tried \\menu.txt but to no avail. Even placing the .txt files in the folder with the .class files, .java and anywhere else doesnt seem to work :(
# 4 Re: Simple FileNotFoundException
sorry, just try "./menu.txt". i forgot, that \ is the escape character.
# 6 Re: Simple FileNotFoundException
Put the full path to the file in the filename.
What library files/classes have you imported?
nspils at 2007-11-11 22:40:17 >

# 9 Re: Simple FileNotFoundException
Have you put the entire path to the file in your "filename"? If so, what was the result?
Have you tried FileInputStream? (The benefit of FileReader is that it reads the content as characters rather than bytes which then need to be converted)
nspils at 2007-11-11 22:43:27 >
