tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Kaufman <WKauf...@viquity.com>
Subject RE: file reading and writing
Date Wed, 04 Apr 2001 13:38:45 GMT
> A call to 
> getServletContext().getAttribute("javax.servlet.context.tempdir") 
> returns:
> jakarta-tomcat-3.2.1/work/localhost_8080

Did you intend to put output.txt in the temp directory?  AFAIK, it won't go
there by default: you'll need to specify that directory, like,

    String tmpdir =
      getServletContext().getAttribute("javax.servlet.context.tempdir");
    File f =
      new File(tempdir, "output.txt");
    DataOutputStream fileOut =
      new DataOutputStream( new FileOutputStream(f));
                                                            -- Bill K.


> -----Original Message-----
> From: Brian Teutsch [mailto:b-teutsch@northwestern.edu]
> Sent: Tuesday, April 03, 2001 8:45 PM
> To: tomcat-user@jakarta.apache.org
> Subject: file reading and writing
> 
> 
> I am trying to control some file reading and writing. I'm trying to 
> transition some servlets from QuidProQuo, and the primary 
> difficult I am 
> having is figuring out how to read and write a file. I've 
> tried to debug 
> everything I can think of, mostly the permissions on all the work 
> directories (localhost_8080* all set to rwx). Getting 
> accustomed to OS 
> X, I know that permissions can be a big sticking point. Although it 
> could be something else completely, despite the error.
> 
> Here's the code I am trying in a simple servlet.
> --
> DataOutputStream fileOut;
> fileOut = new DataOutputStream( new FileOutputStream("output.txt"));
> fileOut.writeBytes("test");
> fileOut.close();
> --
> A call to 
> getServletContext().getAttribute("javax.servlet.context.tempdir") 
> returns:
> jakarta-tomcat-3.2.1/work/localhost_8080
> 
> And the servlet catches the exception:
> java.io.FileNotFoundException: output.txt (Permission denied)
> 
> So, where does the servlet store things it wants to access? I'm just 
> looking for something simple here, until I have the time to learn jar 
> file access in general. Hopefully I'm just missing something in the 
> development or config docs.
> 
> Brian Teutsch
> 

Mime
View raw message