Kristian
Kristian

Reputation: 1239

Java reading txt.file - access denied?

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

Answers (4)

user207421
user207421

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

user3621271
user3621271

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

Naveen Babu
Naveen Babu

Reputation: 1584

there could be 2 types of issue.

  1. your path is containing space in folder or file name. you can solve it by using the non-8dot3 file name by using the command dir /p /x in command prompt of that folder path.
  2. you can save the form in your project folder and use relative 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

Ashwinee K Jha
Ashwinee K Jha

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

Related Questions