[java] java.io.FileNotFoundException: (Access is denied)

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.

Exception in thread "main" java.io.FileNotFoundException: C:\backup (Access is denied)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)

This question is related to java filenotfoundexception access-denied

The answer is


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.


  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

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.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to filenotfoundexception

open failed: EACCES (Permission denied) java.io.FileNotFoundException: the system cannot find the file specified Java - Access is denied java.io.FileNotFoundException Java says FileNotFoundException but file exists Python open() gives FileNotFoundError/IOError: Errno 2 No such file or directory FileNotFoundException while getting the InputStream object from HttpURLConnection java.io.FileNotFoundException: (Access is denied)

Examples related to access-denied

pip install access denied on Windows Getting "java.nio.file.AccessDeniedException" when trying to write to a folder mysqldump Error 1045 Access denied despite correct passwords etc Hosting ASP.NET in IIS7 gives Access is denied? MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES) Access to the path 'c:\inetpub\wwwroot\myapp\App_Data' is denied Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar IIS Express gives Access Denied error when debugging ASP.NET MVC Access to the path denied error in C# Unable to copy file - access to the path is denied