When Java code opens a file it is not allowed to touch, the exception is often disguised: java.io.FileNotFoundException: /path/to/file (Permission denied) reads as if the file were missing, while the parenthetical gives the real reason. The JVM runs as some operating-system user, and that user lacks read or write permission on the file, write permission on the directory (for creating or renaming files), or execute (search) permission on a directory along the path. The code is usually fine; the identity the process runs as, and the file's ownership, disagree.
whoami in the same context, the service definition, or System.getProperty("user.name") logged by the app). Every permission question is about this user, not the developer's login.ls -l the file and namei -l /full/path to see permissions along the whole chain; a single directory without execute permission for this user blocks everything beneath it. On Windows, check the file's Security tab and whether the folder is protected (system folders, another user's profile).audit.log, dmesg) records those denials.chown) or add the minimal permission (chmod) on the file or directory involved; prefer ownership by the service account for application data directories.chmod 777, removes the error by removing the protection; both leave the system exposed and hide the real configuration mistake.Why does it say FileNotFoundException when the file exists? FileInputStream and FileOutputStream historically report open failures through FileNotFoundException, appending the operating system's reason in parentheses. “(Permission denied)” in that message means the file was found and refused, not missing.
It works when I run it, but fails as a service, why? Different users. Your shell runs as you; the service runs as its service account (often with minimal rights), and the file is owned by you. The service user's permissions are the ones that matter.
The permissions look right but it still fails, what else? Check the directories above the file (a common blind spot), Windows file locks by another process, and on Linux the security modules (SELinux/AppArmor) whose denials appear in system logs rather than in ls output.