尽管 chmod 777,java.io.FileNotFoundException(权限被拒绝) [英] java.io.FileNotFoundException (permission denied) despite chmod 777
问题描述
我在编写部署在 Tomcat 上的 Grails 应用程序时遇到了奇怪的问题.
I have faced strange poblem while writing Grails application deployed on Tomcat.
创建简单的测试控制器后,我想在其中编写测试内容包com
After creating simple test controller I want to write test contents in package 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);
}
}
}
我得到一个例外:
类 java.io.FileNotFoundException 消息/home/user/domains/domain.com/public_html/the-file-name.txt (Brakdostępu)
Class java.io.FileNotFoundException Message /home/user/domains/domain.com/public_html/the-file-name.txt (Brak dostępu)
我已将 chmod 设置为 777 到 /home/user/domains/domain.com/public_html/
.而 tomcat7.tomcat7
是所有者.我也尝试使用访问权限 777 和设置为 tomcat7 的所有权创建此文件,但我仍然遇到异常:
I have set the chmod to 777 into /home/user/domains/domain.com/public_html/
. And tomcat7.tomcat7
is owner. I have also tried to create this file with the access rights 777 and ownership set to tomcat7, but I still get an exception:
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?
如果有人能澄清问题,我将不胜感激.
I would be very gratefull if someone could clarify the problem.
编辑:
我在/path1
下创建了目录,设置为777.文件保存完好.我也在 /path2/testdir
下创建了目录,但是 path2 没有权限 777 和 chown.它也有效.我还测试了带有字符 .
和 _
的 testdir
,也可以使用.
I have created the directory under /path1
, set 777. The files are stored perfectly.
I have also crated the directory under under /path2/testdir
, but path2 has no permission 777 and chown. It also works. I have also testes the testdir
with characters .
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.
示例:chmod o+x/home/user
这篇关于尽管 chmod 777,java.io.FileNotFoundException(权限被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!