英文:
java.io.IOException: Permission denied cannot create file in Linux
问题
我正在尝试在Linux系统中的/opt/ie/var/tmp目录下创建临时文件,/opt/ie/var/tmp目录的权限为drwxr-xr-x。在创建时,我遇到了java.io.IOException: Permission denied无法创建文件的错误。以下是我的代码:
File uploadedFile = File.createTempFile(prefix, suffix, new File("/opt/ie/var/tmp"));
是否有办法在Java中在创建临时文件时设置sudo权限?谢谢。
英文:
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
得分: 1
你正在使用一个共享的 tmp
目录,所以我认为应该给它适当的权限:
chmod 1777 /opt/ie/var/tmp
附注:我从Linux Mint系统使用 stat /tmp
得到了 1777/drwxrwxrwt
。其中的 t
代表了“受限删除标志”或“粘性位 (sticky bit)”。
英文:
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)
.
答案2
得分: 0
你可以从根用户运行你的Java应用程序,然后它应该能够创建该文件。
英文:
You can run your java application from root user, then it should be able to create the file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论