0

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.

1
  • 2
    How are you logged in? Are you the owner of the tmp folder 'cause that's the only user with permission to write there. Commented Aug 28, 2020 at 19:46

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Expanding on this answer, assuming root owns the folder, then only root has permission to write a file there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.