Results 1 to 7 of 7
  1. #1
    carlodelmundo is offline Member
    Join Date
    Aug 2008
    Posts
    31
    Rep Power
    0

    Default Eclipse Bug - Can't Read From A File Using Eclipse?

    Hi.

    Is there a known bug for this? In my CompSci class, we were asked to read text from a while. I was succesful doing it in Notepad and manually compiling, but when I use the Eclipse IDE to do it (and place the .txt file in the same src folder as the class), it complains that it "Can't Find File".

    Is this a known bug?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Yep, it's a bug, but it's in your code. You need to know what directory the program is looking in. It's not where you think it is or you've got the name wrong or something, but it has nothing to do with Eclipse. Trust me, the creators of Eclipse are a lot smarter than you or me.

  3. #3
    carlodelmundo is offline Member
    Join Date
    Aug 2008
    Posts
    31
    Rep Power
    0

    Default

    I see. So when I use a File Object (I use scanner to read from the file), I have to supply the direct path from my Windows computer?

    So, in essence, there's no "default" folder that Eclipse looks at?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This really has nothing to do with Eclipse and everything to do with Java. To find out which directory Java is using to look for your file, I'd call
    Java Code:
    System.out.println(System.getProperty("user.dir"));

  5. #5
    carlodelmundo is offline Member
    Join Date
    Aug 2008
    Posts
    31
    Rep Power
    0

    Default

    My god. Thank you for that. It appears that it looks for it in my workspace folder that I designated @ the beginning of installation of Eclipse.

    Kudos, friend.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    glad it helped. happy coding.

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    First, if you put the file in your src folder, Eclipse will copy it to your bin folder, because Eclipse assumes it's some sort of resource.

    Here's a good trick for finding resources you have placed in your application. The bin directory is one of the entries in your classpath.
    Java Code:
    URL fileURL = ClassLoader.getSystemClassLoader.getResource("/filename.txt");
    File file = new File(fileURL.toURI());
    Note the use of "/" as directory delimeters. This will search the entire classpath for your resource, so you don't have to know exactly where it is.

Similar Threads

  1. Replies: 4
    Last Post: 01-08-2009, 10:26 PM
  2. jsp file in Eclipse
    By nagaprasanna in forum Eclipse
    Replies: 0
    Last Post: 11-18-2008, 08:21 AM
  3. eclipse batch file
    By doug99 in forum Eclipse
    Replies: 6
    Last Post: 04-24-2008, 02:59 PM
  4. How to run/build the JSP file using Eclipse
    By cbklp in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-19-2008, 12:03 AM
  5. An Introduction to Eclipse PDE - File Creation
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-09-2007, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •