Access denied error when trying to create a tmp file in Java on Windows NT

java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.checkAndCreate(File.java:1345)
at java.io.File.createTempFile(File.java:1434)
Cause:
When you try to create a tmp file in java for exclusive use in Windows operating system

Solution:
There are a number of reasons you could get this error.
  1. You have a multi-threaded program and two threads are trying to create the same file. This is a logical error, the solution is to recheck your logic (put a mutex!)
  2. You don't have access to the path. Read only?
  3. If neither of the above checks out, then check if the file you are trying to create already exists. If it does, delete it and try again. This worked for me

0 comments:

Post a Comment