|
Re: FileNotFound [message #1010248 is a reply to message #1010174] |
Sun, 17 February 2013 01:00 |
|
On 02/16/2013 02:37 PM, Sally Budack wrote:
> I am trying to access a file in the source folder. When I use another
> editor with the same code, it works. I cannot find a reason it does not
> in Eclipse. All of my other code works. I have tried other files
> without success. I unistalled & reinstalled Eclipse. It still does not
> work. Any Suggestions?
>
> Exception in thread "main" java.io.FileNotFoundException: mobydick.txt
> (The syst
> em cannot find the file specified)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(Unknown Source)
> at java.util.Scanner.<init>(Unknown Source)
> at HWo5Main.main(HWo5Main.java:17)
>
>
> Exception in thread "main" java.io.FileNotFoundException: Numbers.txt
> (The syste
> m cannot find the file specified)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(Unknown Source)
> at java.util.Scanner.<init>(Unknown Source)
> at WrapperClass.readFile(WrapperClass.java:32)
> at CH10Main.main(CH10Main.java:22)
>
> Any help would be appreciated.
Your question is a bit misleading. In fact, you're not trying to open a
file with an editor, but from code you've written in Java, no? The fact
that you can use an editor to open the file successfully is neither here
nor there (apples and oranges).
This is really more a Java--not Eclipse--question. As such, you should
ask it in a Java forum like javaranch.com, jguru.com or
stackoverflow.com. Or Google for the answer.
What you're missing, however, is an understanding of how the path works
relative to, in this case an Eclipse project, but it's a similar problem
no matter what IDE you're using (or even with no IDE at all).
For many reasons, Java is a lot harder to use for file I/O than what
other languages like C offer. If you were to move mobydick.txt to
C:\eclipse (or wherever you've installed Eclipse) or to the root of your
project, you'd probably find that your code works. Otherwise, you'll
have to do some serious study on how Java I/O works.
Many, many years ago, when I was in Java short pants, I wrote this note
to myself:
http://www.javahotchocolate.com/topics/pfileio.html
Here are some good (probably better) links to read on this topic:
http://stackoverflow.com/questions/437382/how-do-relative-file-paths-work-in-eclipse
http://docs.oracle.com/javase/tutorial/essential/io/path.html
http://www.mkyong.com/java/how-to-construct-a-file-path-in-java/
http://www.avajava.com/tutorials/lessons/whats-the-difference-between-a-files-path-absolute-path-and-canonical-path.html
I hope some of this helps.
Best of luck.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10087 seconds