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

标签 java tomcat grails ioexception filenotfoundexception

我在编写部署在 Tomcat 上的 Grails 应用程序时遇到了奇怪的问题。

创建简单的测试 Controller 后,我想将测试内容写入 包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);
                }
        }
}

我得到一个异常(exception):

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

我已在 /home/user/domains/domain.com/public_html/ 中将 chmod 设置为 777。 tomcat7.tomcat7 是所有者。我也尝试使用访问权限 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

我还应该满足操作系统中的哪些条件?

如果有人能澄清这个问题,我将非常感激。


编辑:

我在/path1下创建了目录,设置为777。文件保存完好。 我也在/path2/testdir下创建了目录,但是path2没有权限777和chown。它也有效。我还用字符 ._ 测试了 testdir,也可以。

我非常善于调查,无法理解这种行为。

最佳答案

确保您也拥有对所有父目录的读取和执行权限。

示例: chmod o+x/home/user

关于java.io.FileNotFoundException(权限被拒绝)尽管 chmod 777,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21008976/

相关文章:

java - Android - 适用于所有语言的正确字符串编码

tomcat - 在哪里保存 ActiveMQ 数据?

html - 如何获取 Angular 的grails数组

grails - 如何在Grails中实现动态 View 属性

java - 为什么字符串长度-1

java - mybatis中如何修复 "Invalid bound statement (not found)"?

java - 与 32 位 tomcat 相比,使用 64 位 tomcat 是否可以提高性能?

Tomcat管理器远程部署脚本

hibernate - Grails-使用CreateCriteria执行WHERE IN子查询

java - 为什么 MimetypesFileTypeMap 总是为 PNG 文件返回 "application/octet-stream"?