简体   繁体   English

File.createNewFile()给出java.io.IOException:权限被拒绝

[英]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.

相关问题 java.io.IOException:createNewFile() 的权限被拒绝 - java.io.IOException: Permission denied for createNewFile() java.io.IOException:Java中的权限被拒绝 - java.io.IOException: Permission denied in Java java.io.IOException:权限被拒绝无法在 Linux 中创建文件 - java.io.IOException: Permission denied cannot create file in Linux java.io.IOException:权限被拒绝但文件已创建 - java.io.IOException: Permission denied but file is created File.createNewFile() 抛出 IOException 没有这样的文件或目录 - File.createNewFile() thowing IOException No such file or directory 即使在询问权限后,java.io.IOException 权限也被拒绝 - java.io.IOException Permission denied even after asking the permision java.io.IOException:关闭XSSFWorkbook时,jenkins中的权限被拒绝 - java.io.IOException: Permission denied in jenkins While Closing XSSFWorkbook java.io.IOException:在Andoid上使用相机时权限被拒绝? - java.io.IOException: Permission denied when using Camera on Andoid? 在android/java中调用createNewFile()时,为什么会出现:java.io.IOException: No such file or directory - When calling createNewFile() in android/java, why do I get: java.io.IOException: No such file or directory java.io.IOException:权限被Lan唤醒拒绝 - java.io.IOException: Permission denied with Wake on Lan
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM