[英]File.createNewFile() gives java.io.IOException: Permission denied
My OS is fedora and I use the following code to create a file: 我的操作系统是fedora,我使用以下代码创建文件:
String destFile = "/var/www/html/nykkos/app/webroot/AssimilatorGenerator/Script_May6/db/"+"musics.db";
File destinationFile= new File(destFile);
if(!destinationFile.exists()) {
destinationFile.createNewFile();
}
It gives me the following exception at the line destinationFile.createNewFile()
它在行destinationFile.createNewFile()
处给了我以下异常
java.io.IOException: Permission denied
Why this exception occurs and how can I overcome the same? 为什么会发生这种异常,我该如何克服呢?
sudo chmod a+rwx /var/www/html/nykkos/app/webroot/AssimilatorGenerator/Script_May6/db
changes the rights for all to the directory. sudo chmod a+rwx /var/www/html/nykkos/app/webroot/AssimilatorGenerator/Script_May6/db
更改目录的所有权限。 Better look first whether chown
, changing the owner/group might do. 最好先查看chown
,更改所有者/组是否可以。 Or a combination of same group and giving the group all rights. 或同一组的组合并赋予该组所有权利。
BTW createNewFile is seldom needed. 几乎不需要BTW createNewFile。
It is probably because the user you are running the JVM with has not the right permission to write at that path. 可能是因为运行JVM的用户没有在该路径上进行写入的权限。 But please post more deatils for a better answer. 但请发布更多详细信息以获得更好的答案。
You have to check owner
mode and permission
setting of parents directories setting. 您必须检查owner
模式和父目录设置的permission
设置。 If there is no write
permission in Your OS, you will get the exception. 如果您的操作系统没有write
权限,您将获得异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.