我无法写入文件
我使用 tomcat5.32 + cpanel 。
我的代码是:
<%
String path = application.getRealPath("");
path +="/as.txt" ;
FileOutputStream fos = new FileOutputStream(path);
fos.write("this is test ?".getBytes());
fos.flush();
fos.close();
%>
当请求时出现此错误:
java.io.FileNotFoundException: /home/domainname/public_html/ROOT/as.txt (Permission denied)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:179)
java.io.FileOutputStream.<init>(FileOutputStream.java:70)
org.apache.jsp.newjsp2_jsp._jspService(newjsp2_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
权限是0644,但我的程序无法写入自己的文件。
请帮我
i use tomcat5.32 + cpanel .
my code is :
<%
String path = application.getRealPath("");
path +="/as.txt" ;
FileOutputStream fos = new FileOutputStream(path);
fos.write("this is test ?".getBytes());
fos.flush();
fos.close();
%>
when requested get this error :
java.io.FileNotFoundException: /home/domainname/public_html/ROOT/as.txt (Permission denied)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:179)
java.io.FileOutputStream.<init>(FileOutputStream.java:70)
org.apache.jsp.newjsp2_jsp._jspService(newjsp2_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
the perms is 0644 but my program can not write in own files .
please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误非常明显,您没有对该文件具有写入权限。
您的许可,
0644
仅向拥有该文件的用户添加读/写
权限。任何一个让您的 Tomcat 用户成为所有者,或将该用户包含到文件组中并应用权限
0664
。The error is quite clear, you don't have write permissions to the file.
Your permission,
0644
addsRead/Write
rights only to the user owning the file. Eithermake your Tomcat user the owner, or include the user to the files group and apply the permission
0664
.1) 确保尝试写入此文件的“用户”实际上具有权限。写入磁盘的 JVM 可能不会使用与启动 JVM 的用户相同的权限。
2) 在尝试写入文件之前,确保该目录路径的所有步骤均实际存在。
1) Ensure that the 'user' that is attempting to write to this file actually has permissions. JVM writing to the disk may not use the same Permissions as the User who launched the JVM.
2) Ensure all steps of that dir path actually exist prior to attempting to write to a file.