typeof programmer
typeof programmer

Reputation: 1609

java.io.IOException: Permission denied cannot create file in Linux

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

Answers (2)

Febtober
Febtober

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

Saurabh Nigam
Saurabh Nigam

Reputation: 823

You can run your java application from root user, then it should be able to create the file.

Upvotes: 0

Related Questions