Simple FileNotFoundException


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 13 of 13

Thread: Simple FileNotFoundException

  1. #1
    Join Date
    Apr 2006
    Posts
    7

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    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)

  3. #3
    Join Date
    Apr 2006
    Posts
    20
    also, you could find out where the .class files are going to after you compile, and throw the text file in there

  4. #4
    Join Date
    Apr 2006
    Posts
    7
    Quote 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

  5. #5
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    sorry, just try "./menu.txt". i forgot, that \ is the escape character.

  6. #6
    Join Date
    Apr 2006
    Posts
    7
    still no luck

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Put the full path to the file in the filename.

    What library files/classes have you imported?

  8. #8
    Join Date
    Apr 2006
    Posts
    7
    import java.net.*;
    import java.util.*;
    import java.io.*;

  9. #9
    Join Date
    Apr 2006
    Posts
    7
    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.

  10. #10
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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 03:57 PM.

  11. #11
    Join Date
    Apr 2006
    Posts
    7
    Putting the full path still generated a FileNotFoundException.

  12. #12
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    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()); ?

  13. #13
    Join Date
    Oct 2005
    Posts
    107
    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

  1. Simple Access DB will not run using VB6
    By wisgro in forum VB Classic
    Replies: 3
    Last Post: 03-03-2006, 08:28 AM
  2. Simple tic tac toe applet
    By Ant_Magma in forum Java
    Replies: 5
    Last Post: 09-26-2005, 04:41 AM
  3. Creating a Simple Combo Box in a Web App
    By Ranchoz71 in forum ASP.NET
    Replies: 3
    Last Post: 04-06-2005, 01:40 PM
  4. Simple VB 6.0 XML parsing
    By slimasian in forum VB Classic
    Replies: 1
    Last Post: 03-02-2005, 02:38 PM
  5. Simple Java DOM question
    By Lenin in forum XML
    Replies: 0
    Last Post: 03-21-2001, 05: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center