• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileNotFound  RSS feed

 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this produce an error? The file is in the same folder as the class trying to open the file.

 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The location of the file will be relative to the current working directory, not the location of the class file. Where are you running "java"?
 
Ke rem
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe the file you have is " inventory.txt " or " Inventory.txt.txt "
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using TextPad to compile and run the programs. How can I be sure of that? It would run the programs from their own directory, right?
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the class that is causing errors in a package? The answer to that and the path of the text file relative to where the package(or class if it does not have an explicit package) would be more helpful.
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running the program from the command line. Then you can be sure of the working directory.
You can also create an instance of java.io.File using the file name and check where the JVM thinks that file is (getCanonicalPath()) and if the file exists at all(exists()).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!