简体   繁体   English

尽管 chmod 777,java.io.FileNotFoundException(权限被拒绝)

[英]java.io.FileNotFoundException (permission denied) despite chmod 777

I have faced strange poblem while writing Grails application deployed on Tomcat.我在编写部署在 Tomcat 上的 Grails 应用程序时遇到了奇怪的问题。

After creating simple test controller I want to write test contents in package com创建简单的测试控制器后,我想在包 com 中编写测试内容

package com.domain.controller

import java.io.File;
import java.io.PrintWriter;

class TestController {

        def index() {
                // test
                try {
                        PrintWriter writer = new PrintWriter("/home/user/domains/domain.com/public_html/the-file-name.txt");
                        writer.println("The first line");
                        writer.println("The second line");
                        writer.close();
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
        }
}

I get an exception:我得到一个例外:

Class java.io.FileNotFoundException Message /home/user/domains/domain.com/public_html/the-file-name.txt (Brak dostępu)类 java.io.FileNotFoundException 消息 /home/user/domains/domain.com/public_html/the-file-name.txt (Brak dostępu)

I have set the chmod to 777 into /home/user/domains/domain.com/public_html/ .我已将 chmod 设置为 777 到/home/user/domains/domain.com/public_html/ And tomcat7.tomcat7 is owner.tomcat7.tomcat7是所有者。 I have also tried to create this file with the access rights 777 and ownership set to tomcat7, but I still get an exception:我还尝试使用访问权限 777 和所有权设置为 tomcat7 创建此文件,但我仍然遇到异常:

ls -al /home/user/domains/domain.com/public_html
razem 16
drwxrwxrwx 3 tomcat7 tomcat7 4096 01-08 23:25 .
drwxr-xr-x 8 user    user    4096 12-16 17:14 ..
-rwxrwxrwx 1 tomcat7 tomcat7    0 01-08 23:25 the-file-name.txt

What conditions in OS should I also meet?我还应该满足 OS 中的哪些条件?

I would be very gratefull if someone could clarify the problem.如果有人能澄清这个问题,我将不胜感激。


EDIT :编辑

I have created the directory under /path1 , set 777. The files are stored perfectly.我在/path1下创建了目录,设置为 777。文件保存完好。 I have also crated the directory under under /path2/testdir , but path2 has no permission 777 and chown.我还在/path2/testdir下创建了目录,但 path2 没有权限 777 和 chown。 It also works.它也有效。 I have also testes the testdir with characters .我还测试了带有字符的testdir . and _ , also works._ ,也有效。

I am very investigative and cannot understand the behaviour.我非常善于调查,无法理解这种行为。

Ensure you that you have read and execute access to all parent directories as well.确保您还拥有对所有父目录的读取和执行访问权限。

Example: chmod o+x /home/user示例: chmod o+x /home/user

Finally I have solved the problem.最后我解决了这个问题。 One of the directory in path haven't executable permission for other group, so as @JustinKSU suggested, there was no possibility to go throught whole path.路径中的目录之一没有其他组的可执行权限,因此正如@JustinKSU 建议的那样,不可能遍历整个路径。

chmod o+x /home/user solved the problem. chmod o+x /home/user解决了这个问题。

FileNotFoundException occurs: FileNotFoundException发生:

when a file with the specified pathname does not exist.当具有指定路径名的文件不存在时。 It will also be thrown if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.如果文件确实存在但由于某种原因无法访问,例如尝试打开只读文件进行写入时,它也会被抛出。

File is there and it has write rights according to what you sent.文件在那里,并且根据您发送的内容具有写权限。

In some cases, if the file that you are trying to access for read/write operation is opened by another program then this error will occur.在某些情况下,如果您尝试访问以进行读/写操作的文件被另一个程序打开,则会发生此错误。 Use lsof | grep the-file-name.txt使用lsof | grep the-file-name.txt lsof | grep the-file-name.txt to see if it is open. lsof | grep the-file-name.txt以查看它是否打开。

I ran into this problem during builds within a Jenkins job.我在 Jenkins 工作中的构建过程中遇到了这个问题。 I had added the jenkins user to the tomcat7 group, yet the Jenkins job failed whenever it was supposed to copy artifacts to the Tomcat instance directory.我已将jenkins用户添加到tomcat7组,但是每当 Jenkins 作业应该将工件复制到 Tomcat 实例目录时,它就会失败。

It turned out all I needed to fix this problem was to restart the Jenkins service.原来我需要解决这个问题就是重新启动 Jenkins 服务。

Same symptoms when you have selinux activated激活selinux时出现相同症状
You can check the status with sestatus and disable it with setenforce 0您可以使用sestatus检查状态并使用setenforce 0禁用它

It may solve your problem in the short term, just make sure it's reboot proof.它可能会在短期内解决您的问题,只需确保它是重启证明即可。

I'm use virtual box 6.1 and macOS Catalina 10.15.5.我使用的是 virtual box 6.1 和 macOS Catalina 10.15.5。

In my case I need to add -R flag.就我而言,我需要添加-R标志。 chmod -R o+x /home/user

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

相关问题 java.io.FileNotFoundException :(权限被拒绝) - java.io.FileNotFoundException: (Permission denied) 错误:Android打包程序:[…] java.io.FileNotFoundException:…(权限被拒绝) - Error:Android Packager: […] java.io.FileNotFoundException:… (Permission denied) java.io.FileNotFoundException:/ mnt / sdcard / file(权限被拒绝) - java.io.FileNotFoundException: /mnt/sdcard/file (Permission denied) 写入SD卡“java.io.FileNotFoundException:Permission denied” - Write to SD card “java.io.FileNotFoundException: Permission denied” java.io.FileNotFoundException:(权限被拒绝)仅在Oreo中 - java.io.FileNotFoundException: (Permission denied) Only in Oreo java.io.FileNotFoundException(访问被拒绝) - java.io.FileNotFoundException(Access is denied) java.io.FileNotFoundException:临时(访问被拒绝) - java.io.FileNotFoundException: Temp (Access is denied) JavaFx:java.io.FileNotFoundException(访问被拒绝) - JavaFx: java.io.FileNotFoundException (Access is denied) java.io.FileNotFoundException访问被拒绝 - java.io.FileNotFoundException Access is denied java.io.FileNotFoundException:(访问被拒绝) - java.io.FileNotFoundException: (Access is denied)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM