Java reading txt.file - access denied?

独自空忆成欢 提交于 2019-12-10 09:46:14

问题


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.

  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.



回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!