java.io.IOException:网络文件夹上的权限被拒绝 [英] java.io.IOException: Permission denied on network folder

查看:1999
本文介绍了java.io.IOException:网络文件夹上的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在安装在unix系统上的窗口文件夹上写入文件时遇到帖子的标题错误。我开发了一个在Linux操作系统上运行Tomcat 6的Web服务,需要在Windows网络文件夹上编写。系统管理员已将其安装在Linux服务器上,并且在其上创建和修改文件没有问题。
当我尝试执行发布的代码时,我得到以下异常:

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 :

权限被拒绝
java.io.IOException:权限被拒绝
在java.io.UnixFileSystem.createFileExclusively(本机方法)
在java.io.File.createNewFile(File.java:850)

Permission denied java.io.IOException: Permission denied at java.io.UnixFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(File.java:850)

奇怪的事情它似乎与网络文件夹上的File.createNewFile方法有关,实际上该服务可以在本地文件系统上写入而没有问题,无论是在调试(用于开发服务的PC)还是tomcat文件夹系统管理员在linux服务器上提供了我。文件已创建但为空,并且不会打印create方法后面的日志条目。此外,如果我使用普通的输出流创建和写入文件我没有问题。

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.

我在网上找不到任何关于例外的解释。由于我对java不是很有经验,我想知道为什么我会收到这个错误。我是以错误的方式使用它吗?这是图书馆的错误吗?我想错过传递一些参数吗?
如上所述,我使用普通的输出流解决了这个问题,这是一个提高我对java的理解的问题。

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)); 

提前感谢您的回答

推荐答案

我最近遇到了这个问题,发现java.io.File.createNewFile()实际上需要更改权限权限(检查时可以在Security-> Advanced下找到此条目文件夹权限)。如果没有它,它将创建文件,然后抛出IOException。

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.

这是欺骗性的,因为在手动测试时你仍然可以在文件夹上创建文件,但是createNewFile( )如果它没有这个特殊的权限,它仍然会失败(可能是因为它可以改变它创建的文件的权限)。

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).

这篇关于java.io.IOException:网络文件夹上的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆