简体   繁体   English

Java的。 在Linux中以root身份保存文件

[英]Java. Save file as root in Linux

如何在具有root访问权限的文件夹中保存java应用程序生成的文件?

The straight forward way to do that is to run your application as the root user. 直接的方法是以root用户身份运行您的应用程序。

Another solution is to ask to the user the root password. 另一种解决方案是向用户询问root密码。 To do that, you have to ask the "su" command of your system. 为此,您必须询问系统的“su”命令。 Be careful, your user must have the "wheel" group. 请注意,您的用户必须拥有“wheel”组。 Or, you can use sudo (make sure that sudo is installed and configured for the current user). 或者,您可以使用sudo(确保为当前用户安装和配置了sudo)。

As caarlos0 said in the comments, you can use "kdesu" or "gtksu/gksudo" if you prefer. 正如caarlos0在评论中所说,如果您愿意,可以使用“kdesu”或“gtksu / gksudo”。

Of course, your application is not portable ! 当然,您的应用程序不可移植! On windows, there's no "su", "sudo", etc. 在Windows上,没有“su”,“sudo”等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM