• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't read file  RSS feed

 
Larissa Perkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that needs to read from a file, but I can't even get it to open. I have tried saving the .txt file 2 different ways. First, I saved the file to my src/package folder. Then I tried just the src folder. Then I tried going through Import/general/filesystem/ and selecting the root directory (suggested at another forum). However, my program is still unable to open the file.



What am I doing wrong? How/where should I put the file?
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest you try:



That will tell you EXACTLY where the computer is looking for the file, and whether it thinks there is a file actually there or not.
Both of these methods are in the API for java.io.File.

Also consider renaming your Scanner variable. The fact you called it 'file' confused me for a couple of minutes :-)
 
Larissa Perkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks. I changed the file variable name.

But still not working.

I get the path where I located the file. But fileExists: is false.
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the path is exactly the same?

Spelt exactly the same?
What filename are you looking for? Can you show an example of your program output?
If you are on windows, does it have the option to "hide extensions for known file types" switched on? What windows is showing as "myFile.txt" might actually be "myFile.txt.txt" to the computer.
 
Larissa Perkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crud. I got it. It turns out that it was a .txt.txt

I had a feeling it was something stupid like that.

Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!