java.io.IOException: 在Linux中无法创建文件,权限被拒绝

huangapple go评论82阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月29日 03:34:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63639925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定