Reputation: 1609
I am trying to create a temporary file under /opt/ie/var/tmp in linux, the permission for /opt/ie/var/tmp is drwxr-xr-x. I got java.io.IOException: Permission denied cannot create file when creating, below is my code:
File uploadedFile = File.createTempFile(prefix, suffix, new File("/opt/ie/var/tmp"));
Is there any way I can set sudo when creating the temp file in Java? Thanks.
Upvotes: 0
Views: 2324
Reputation: 110
You are using a shared tmp
directory, so I think the proper thing to do is to give it a proper permission:
chmod 1777 /opt/ie/var/tmp
P.S. I got 1777/drwxrwxrwt
using stat /tmp
from a Linux Mint system. The t
is restricted deletion flag or sticky bit (t)
.
Upvotes: 1
Reputation: 823
You can run your java application from root user, then it should be able to create the file.
Upvotes: 0