java.io.FileNotFoundException: (Access is denied)

前端 未结 4 1529
暗喜
暗喜 2020-11-27 06:35

I am trying to read the files inside a folder, but when I run the program it throws this exception. I tried with some other folders also. It throws the same exception.

相关标签:
4条回答
  • 2020-11-27 06:56
    1. check the rsp's reply
    2. check that you have permissions to read the file
    3. check whether the file is not locked by other application. It is relevant mostly if you are on windows. for example I think that you can get the exception if you are trying to read the file while it is opened in notepad
    0 讨论(0)
  • 2020-11-27 06:56

    Also, in some cases is important to check the target folder permissions. To give write permission for the user might be the solution. That worked for me.

    0 讨论(0)
  • 2020-11-27 07:04

    You cannot open and read a directory, use the isFile() and isDirectory() methods to distinguish between files and folders. You can get the contents of folders using the list() and listFiles() methods (for filenames and Files respectively) you can also specify a filter that selects a subset of files listed.

    0 讨论(0)
  • 2020-11-27 07:05

    Here's a gotcha that I just discovered - perhaps it might help someone else. If using windows the classes folder must not have encryption enabled! Tomcat doesn't seem to like that. Right click on the classes folder, select "Properties" and then click the "Advanced..." button. Make sure the "Encrypt contents to secure data" checkbox is cleared. Restart Tomcat.

    It worked for me so here's hoping it helps someone else, too.

    0 讨论(0)
提交回复
热议问题