user260192
user260192

Reputation:

java.io.IOException: Permission denied on network folder

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

Upvotes: 7

Views: 20788

Answers (3)

oluies
oluies

Reputation: 17831

If you are using Netapp that shares an NTFS (CIFS) style filesystem to Unix you could be experience "NFS is not allowed to change permissions on a file in an NTFS-style security volume." (TR-3490 page 16)

Options here are to change to a unix filesystem or set the cifs.ntfs_ignore_unix_security_ops flag to on for the file system which quiches the NFS permission error.

java.io.UnixFileSystem.createFileExclusively(Native Method) opens the file with the O_EXCL and 0666 umask so I would get a EACCES, which really was a NFS3RR_ACCES

open("/net/storage01-a/filer/myfile", O_RDWR|O_CREAT|O_EXCL, 0666) Err#13 EACCES

Also you can use OutputStream to create the file, that does not use O_EXCL it seemes

Upvotes: 3

Armin Sadeghi
Armin Sadeghi

Reputation: 845

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

Upvotes: 5

AlexR
AlexR

Reputation: 115378

It definitely not Java specific problem. If this Unix folder is mapped to your windows try to open file explorer and create file in this directory. I believe that you will get permission denied too. In this case fix this problem or ask your system administrator to help you.

Good luck!

Upvotes: 2

Related Questions