-
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
-
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)
-
also, you could find out where the .class files are going to after you compile, and throw the text file in there
-
 Originally Posted by graviton
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
-
sorry, just try "./menu.txt". i forgot, that \ is the escape character.
-
-
Put the full path to the file in the filename.
What library files/classes have you imported?
-
import java.net.*;
import java.util.*;
import java.io.*;
-
anyone know if theres any other type of filestreams that work the same way? Slightly annoying how this isnt working when theres no actual reason for it.
-
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)
Last edited by nspils; 04-18-2006 at 02:57 PM.
-
Putting the full path still generated a FileNotFoundException.
-
hmm. did you use "/" instead of "\" symbols for the full path? can you test the existence of that file by doing System.out.println(new File("myfile").exists()); ?
-
are you positive your file is named "menu.txt" maybe you named it "menu.txt.txt" and you have known file extensions hidden?
Similar Threads
-
By wisgro in forum VB Classic
Replies: 3
Last Post: 03-03-2006, 07:28 AM
-
By Ant_Magma in forum Java
Replies: 5
Last Post: 09-26-2005, 03:41 AM
-
By Ranchoz71 in forum ASP.NET
Replies: 3
Last Post: 04-06-2005, 12:40 PM
-
By slimasian in forum VB Classic
Replies: 1
Last Post: 03-02-2005, 01:38 PM
-
Replies: 0
Last Post: 03-21-2001, 04:01 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks