Results 1 to 7 of 7
- 01-25-2009, 05:08 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 31
- Rep Power
- 0
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?
-
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.
- 01-25-2009, 05:22 PM #3
Member
- Join Date
- Aug 2008
- Posts
- 31
- Rep Power
- 0
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?
-
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"));
- 01-25-2009, 05:29 PM #5
Member
- Join Date
- Aug 2008
- Posts
- 31
- Rep Power
- 0
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.
-
glad it helped. happy coding.
- 01-26-2009, 04:25 PM #7
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.
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.Java Code:URL fileURL = ClassLoader.getSystemClassLoader.getResource("/filename.txt"); File file = new File(fileURL.toURI());
Similar Threads
-
Eclipse can't find my image file when generating HTML
By Mateo1041 in forum EclipseReplies: 4Last Post: 01-08-2009, 10:26 PM -
jsp file in Eclipse
By nagaprasanna in forum EclipseReplies: 0Last Post: 11-18-2008, 08:21 AM -
eclipse batch file
By doug99 in forum EclipseReplies: 6Last Post: 04-24-2008, 02:59 PM -
How to run/build the JSP file using Eclipse
By cbklp in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 01-19-2008, 12:03 AM -
An Introduction to Eclipse PDE - File Creation
By JavaForums in forum EclipseReplies: 0Last Post: 05-09-2007, 06:40 AM


LinkBack URL
About LinkBacks

Bookmarks