问题
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.
回答1:
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.
回答2:
java.io.FileNotFoundException: C:\Users\Kristian\Documents (Access is denied)
You are trying to read a directory, not a .txt file.
回答3:
there could be 2 types of issue.
- 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. - 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.
回答4:
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.
来源:https://stackoverflow.com/questions/7894032/java-reading-txt-file-access-denied