Reputation: 1239
I have created a txt
file which I have saved in My Documents on my computer. I am trying to read the txt
file through FileReader
and BufferedReader
. However, when I try to run the program I get the error message:
java.io.FileNotFoundException: <filelocation> (Access is denied)
Does anyone know what causes this, and how I might fix the problem? I have tried saving the document other places too, but I always get this message. I am sure the file path is correclty entered.
Upvotes: 6
Views: 28002
Reputation: 310868
java.io.FileNotFoundException: C:\Users\Kristian\Documents (Access is denied)
You are trying to read a directory, not a .txt file.
Upvotes: 12
Reputation: 11
Could be that you have to change the security settings on your folder. Go into the directory, right click properties, select Security , advances and change permission so that all child dependencies inherit the security changes.
Upvotes: -1
Reputation: 1584
there could be 2 types of issue.
dir /p /x
in command prompt of that folder path../txt.file
. if you have the file under a path say <project folder>/input/txt.file
, your relative path will be ./input/txt.file
. If this doesn't work try googling the code for file reading and you will find out your mistake.Upvotes: 0
Reputation: 9307
One random guess is that you may be having multiple instance of your test program running so the file is locked by earlier instance of your program which is still running. You can check open consoles in the eclipse or you can restart eclipse.
Upvotes: 5