You could stream it directly to the user, if practical (why write to a temp file only to stream that back to the user?) In order to be recognized by the browser as text and an attachment, you should:
response.setContentType("text/plain; charset=UTF-8"); response.setHeader("Content-disposition", "attachment; filename=xxxx.txt"); charset is optional... Tim -----Original Message----- From: David Kerber [mailto:[EMAIL PROTECTED] Sent: Friday, October 13, 2006 10:13 PM To: Tomcat Users List Subject: Writing a text file back to browser from a servlet I'm trying to do something that seems like it should be very easy, but can't get it to work: sending a .txt file back to the user's browser so they can save it to their local hard disk. I am having no trouble creating the file and writing it to a temporary place on the server, but can't figure out what I need to do so the users can save the result. Right now, I'm using the following code excerpt: fReader = new FileReader( fullFileName ); bReader = new BufferedReader( fReader ); oStream = response.getOutputStream(); while (( logString = bReader.readLine()) != null ) { // I'm sure a println would also work, but this is what I happen to have right now oStream.write(( logString + EddRcvr.newLineStr ).getBytes()); } oStream.close(); bReader.close(); fReader.close(); And it *displays* just fine in the browser window, but when I try to save it (using firefox 1.5.x), the download windows says it completed successfully, but the file is never there when I try to look at it. Any suggestions as to what I'm missing? TIA! Dave --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]