java.io.IOException:网络文件夹的权限被拒绝
当我尝试在安装在 unix 系统上的窗口文件夹中写入文件时,我遇到了帖子标题错误。我开发了一个 Web 服务,该服务在 Linux 操作系统上的 Tomcat 6 内运行,并且需要在 Windows 网络文件夹上写入。系统管理员已将其安装在Linux服务器上,并且在其上创建和修改文件没有问题。 当我尝试执行发布的代码时,出现以下异常:
权限被拒绝 java.io.IOException:权限被拒绝 在 java.io.UnixFileSystem.createFileExclusively(本机方法) 在 java.io.File.createNewFile(File.java:850)
奇怪的是,它似乎与网络文件夹上的 File.createNewFile 方法有关,实际上该服务可以毫无问题地在本地文件系统上写入,两者调试(我用来开发服务的电脑)和系统管理员在Linux服务器上为我提供了一个tomcat文件夹。该文件已创建,但为空,并且不会打印创建方法后面的日志条目。此外,如果我使用普通的输出流来创建和写入文件,我就没有问题。
我在网上找不到有关异常的任何解释。由于我对 java 不太有经验,我想了解为什么会出现此错误。我是否以错误的方式使用它?这是图书馆的错误吗?我是否错过传递一些参数? 如前所述,我已经使用普通输出流解决了问题,这是一个提高我对 java 的理解的问题。
FileOutputStream fos = null;
try{
log.info(String.format("file length: %s",streamAttach.length));
log.info(String.format("check File : %s",filename));
File f = new File(filename);
if(f.exists())
...
boolean done= f.createNewFile();//here comes the exception
//nothing of the following happens
if(!done)
throw new NWSException("error creating file");
log.info(String.format("file %s creato", nomeFile));
预先感谢您的任何答复
i'm having the the post's title error when trying to write a file on a window folder , mounted on unix system. I've developed a web service which runs inside a Tomcat 6 on a linux os and need to write on a windows network folder. System administrators have mounted it on the Linux sever and have no problem to create and modify a file on it.
When i try to execute the posted code i get the following exception :
Permission denied
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
The weird thing is that it seems to be related to the File.createNewFile method on a network folder , in fact the service can write on local file system without problems, both on debug (the pc i use to develop the service) and a tomcat folder system administrators have provided me on the linux server. The file gets created but is empty and the log entry following the create method doesn't get printed. Moreover if i use a plain outputstream to create and write the file i've no problems.
I cannot find any explanation about the exception on the web. Since i'm not very experienced with java , i'd like to understand why i'm getting this error. Am i using it in the wrong way ? Is it a bug of the library ? Do i miss to pass some parameter ?
As stated , i've solved the problem using a plain outputstream, this is a question to improve my understanding of java.
FileOutputStream fos = null;
try{
log.info(String.format("file length: %s",streamAttach.length));
log.info(String.format("check File : %s",filename));
File f = new File(filename);
if(f.exists())
...
boolean done= f.createNewFile();//here comes the exception
//nothing of the following happens
if(!done)
throw new NWSException("error creating file");
log.info(String.format("file %s creato", nomeFile));
thank you in advance for any answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
如果您使用与 Unix 共享 NTFS (CIFS) 样式文件系统的 Netapp,您可能会遇到“不允许 NFS 更改 NTFS 样式安全卷中文件的权限”的情况。 (TR-3490 第 16 页)
此处的选项是更改为 unix 文件系统或设置 cifs.ntfs_ignore_unix_security_ops 将文件系统标志设置为 on,以消除 NFS 权限错误。
java.io.UnixFileSystem.createFileExclusively(Native Method)
使用 O_EXCL 和 0666 umask 打开文件,这样我会得到一个 EACCES,这实际上是一个 NFS3RR_ACCES< /strong>
open("/net/storage01-a/filer/myfile", O_RDWR|O_CREAT|O_EXCL, 0666) Err#13 EACCES
你也可以使用OutputStream来创建文件,看起来不使用O_EXCL
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我最近遇到了这个问题,发现 java.io.File.createNewFile() 实际上需要“更改权限”权限(检查文件夹权限时可以在“安全”->“高级”下找到此条目)。如果没有这个,它将创建该文件,然后抛出 IOException。
这是具有欺骗性的,因为在手动测试时您仍然可以在文件夹上创建文件,但是如果 createNewFile() 没有此特定权限(大概可以更改其创建的文件的权限),它仍然会失败。
I ran into this problem recently and found that java.io.File.createNewFile() actually requires the "Change Permissions" permission (you can find this entry under Security->Advanced when checking folder permissions). Without this it will create the file and then subsequently throw an IOException.
It's deceptive because you will still be able to create files on the folder when manually testing, however createNewFile() will still fail if it doesn't have this particular permission (presumably such that it can change the permissions on the file its creating).