Selasa, 15 April 2014

How to fix java.io.FileNotFoundException: (Access is denied)




Earlier my impression was that java.io.FileNotFoundException: (Access is denied) comes when you try to read a text or binary file for which you don't have permission from Java program but this can also come while you are using jar command. jar command internally use java.util.zip.ZipFile class to open any jar or war file which can throw java.io.FileNotFoundException: (Access is denied). I was trying to see contents of war file which was created using recent build when I stumble upon this error, see the exact command below:






test@dev454:war-store/target jar -tvf maven-eclipse-web-demo

java.io.FileNotFoundException: maven-eclipse-web-demo (Access is denied)

        at java.util.zip.ZipFile.open(Native Method)

        at java.util.zip.ZipFile.<init>(ZipFile.java:127)

        at java.util.zip.ZipFile.<init>(ZipFile.java:88)

        at sun.tools.jar.Main.list(Main.java:979)

        at sun.tools.jar.Main.run(Main.java:224)

        at sun.tools.jar.Main.main(Main.java:1149)










Possible cause of java.io.FileNotFoundException: (Access is denied):



Here are some of the possible cause I checked immediately:





1) See if you have permission to read jar file or not


this is the most obvious reason of java.io.FileNotFoundException: (Access is denied) exception and I didn't had sufficient permission so I immediately provided read, write and execute permission to war file and tried again


but it didn't help it was still throwing that exception.





2) See if some other process is using that file


This could be another possible reason of "java.io.FileNotFoundException: (Access is denied)". in my case I had earlier tried "tar" command to read that file which I suspect hasn't released the file. because after few try it was solved.





Conclusion:



How to fix java.io.FileNotFoundException: (Access is denied)java.io.FileNotFoundException: (Access is denied) obviously show something is wrong with file permissions. if you have sufficient file permission than possible reason both in Windows and Unix is might be some other process is using that file which may prevent jar command to list down contents of war file or extract content of war file. By the way if you are not aware of how to see contents of war file than its good to know that jar file can be used to see contents of both .jar and .war file. I haven't tested .ear file but I am sure jar command can extract that as well because they are kind of zip file.





Other Java troubleshooting tutorial you may like































Source:http://javarevisited.blogspot.com/2012/03/how-to-fix-javaiofilenotfoundexception.html

Tidak ada komentar:

Posting Komentar