Create new file on web server
Hi
I used this code to write a new file on my pc
FileWriter fstream = new FileWriter("a.txt");
BufferedWriter out = new BufferedWriter(fstream);
afer i deploy my jsp on the web hosting, this code does not work.. cannot find the file specified (Permission denied) was the exception if I'm not mistaken..
The only thing I have for authentication is the ftp login. Is there any way to write on the web server?
The web server is running on linux i think
Thanks
[507 byte] By [
winedza] at [2007-11-27 6:54:21]

# 1
If the server hasn't got permissions to write to disk, it hasn't got permissions.
You need to find a folder where you have got write permissions.
Note that right now, you are attempting to write to the current working directory (probably the [TOMCAT]/bin directory) which is not normally a good idea.
TryServletContext application = getServletConfig().getServletContext();
String fileName = application.getRealPath("/WEB-INF/a.txt");
File myFile = new File(fileName);
FileWriter fstream = new FileWriter(myFile);
BufferedWriter out = new BufferedWriter(fstream);
the ServletContext method getRealPath turns a website relative location into a real location on disk. You might have write permissions to your own web directory. Give it a try.
Cheers,
evnafets