Posted by: Chyne on: July 13, 2009
Error exporting data: java.io.FileNotFoundException: /usr/local/temp/backup.zip (Permission denied)
Root Cause
If the log shows the exception ‘FileNotFoundException’ with the ‘Permission Denied’, the main root cause of this error is the file does not being granted for write permission. It means when the user tries to execute an action to write the data into the file and the file does not have a full permission, this exception will be thrown to tell you that you are trying to performing something that violating the permission.
For example, there are some certain user in Tomcat does not have the write permission to a specific file. If the log shows the information such as ‘user.home’, this will tell you the location of the user directory and which user executing the process:
user.home /usr/share/tomcat5
In this case, the user called ‘tomcat5’ is trying to execute some process to write the data into the directory.
Further Zooming
What is actually the class java.io.FileNotFoundException is trying to do? If just the ‘FileNotFoundException’ exception, the first thing comes into your mind will be the file does not exist in a specific directory. However, this exception will be thrown when the attempt to open the file based on the specified pathname has failed. Besides of the possibility that the specified pathname might not exist that causes this exception to be thrown, another reason will be the file is inaccessible (e.g. the file only has a read-only permission but not for the purpose for writing it).
So, when you see this exception in the future, don’t jump into the conclusion that the file does not exist or keeps struggling of what’s going wrong with the file although the file does exist in the directory. If you are interested to know what does this Class do, you can refer to the following javadocs: