aspose file tools*
The moose likes Servlets and the fly likes permission denied error while creating a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "permission denied error while creating a file" Watch "permission denied error while creating a file" New topic
Author

permission denied error while creating a file

rahul takkallapally
Greenhorn

Joined: Oct 03, 2003
Posts: 6
hi ,
i am trying to create a file using a servlet , this servlet is invoked form an applet , i am getting an exception saying permission denied.. , the code of my program is ...
try {
File outputFile = new File("window_surf_test");
FileOutputStream fos = new FileOutputStream(outputFile);
PrintWriter pwriter = new PrintWriter(fos);
pwriter.println(stringValue1);
pwriter.println(stringValue2);
pwriter.println(stringValue3);
//pwriter.println(f);
System.out.println( " Check the result: " + stringValue2 );
pwriter.close();
fos.close();
} catch (FileNotFoundException e) {
System.err.println("FileStreamsTest: " + e);
stringValue1=e.toString();
}

Please tell me how to resolve this problem .......,
thaks ......
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

windows or linux?

what's the full stack trace say? With I/O errors, there is normally a helpful human-readable message somewhere in the stacktrace.

You're trying to create the file on the server, right?
rahul takkallapally
Greenhorn

Joined: Oct 03, 2003
Posts: 6
yup i am trying to create the file on the server itself , and i put an exception for file not found so i am getting the exception as
file not found : file name , permission denied..
the second question is how do i mention the path where to create the file???

thanks a lot in advance
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

if you're on linux, ensure that the directory permissions allow you to create and modify files.

you specify the path when you create the File object. Send it an absolute path, rather than just the name of the file.
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
also, the servlets may be sandboxed depending on your tomcat install. you may have to edit the .policy files in your tomcat/conf folder to allow writing of files in whatever directory you want!
and to get a relative path you must do this
BufferedReader br = new BufferedReader(new FileReader(getServletContext().getRealPath("WEB-INF/blah.txt")));
if you want an absolute one you do this
BufferedReader br = new BufferedReader(new FileReader("/home/blah/blah.txt"));
just change classes for a writer etc.


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
rahul takkallapally
Greenhorn

Joined: Oct 03, 2003
Posts: 6
hi ,
i changed the permissions of the directory , and gave an absolute path too , but its not working, i am still getting the permisssion deined error. , i am using a unix machine... , the code for creation of the file is something like this..
try {
File outputFile = new File("/usr/internet/httpd/tomcat/webapps/examples/servlets/window_surf_test");
FileOutputStream fos = new FileOutputStream(outputFile);
PrintWriter pwriter = new PrintWriter(fos);
pwriter.println(stringValue1);
pwriter.println(stringValue2);
pwriter.println(stringValue3);
//pwriter.println(f);
System.out.println( " Check the result: " + stringValue2 );
pwriter.close();
fos.close();
} catch (FileNotFoundException e) {
System.err.println("FileStreamsTest: " + e);
stringValue1=e.toString();
}

can u tell me what part of the policy file should i change , i am using tomcat version 1.1
please help

thanks.....
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
1.1? woah, im not sure how 1.x works, but in 4.x you add something like this
grant codeBase "file:/home/virtual/site20/fst/var/www/html/-" {
permission java.security.AllPermission;
};
obviously changing /home/virtual.... to the directory you want to edit.
rahul takkallapally
Greenhorn

Joined: Oct 03, 2003
Posts: 6
thanks a lot for ur replys..........
i went into the conf file and made changes of this sort ,
<Directory "/usr/apache/...">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
</Directory>
it dint work ,i am still getting the permission denied error, can u tell me is what i did right or is there some other way of doing it
please help
thnaks
rahul takkallapally
Greenhorn

Joined: Oct 03, 2003
Posts: 6
thanks a lot every body
i got the solution .........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: permission denied error while creating a file