wood burning stoves 2.0*
The moose likes Java in General and the fly likes Download File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Download File" Watch "Download File" New topic

Download File

Amy Howard
Ranch Hand

Joined: Jul 11, 2002
Posts: 86
My J2EE application enables the users to download files in remote server. I created a stateless session bean which returns a StringBuffer that has the content of the download file. Then I tried to create a temp file to save the content of the file. But the problem is how to read this temp file. I found that it creates different file names use the following code (download****.tmp). Is there a way directly send the StringBuffer to the browse or any editor such as WordPad or NotePad to enable the user to view or download?
// Create temp file.
File temp = File.createTempFile("download", ".tmp");
// Delete temp file when program exits.

// Write to temp file
BufferedWriter out = new BufferedWriter(new FileWriter(temp));
Thanks for the help in advance!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Amy,
Well you could just use a simple swing reader like this:

Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Amy Howard
Ranch Hand

Joined: Jul 11, 2002
Posts: 86
I solved my problem using temp.getAbsolutePath():
stream = new BufferedInputStream(new FileInputStream(temp.getAbsolutePath()));
I agree. Here's the link: http://aspose.com/file-tools
subject: Download File
Similar Threads
unable to locate the Temporary file
reading a stream twice but download it only once
BufferedWriter to byte []
Signed Applet writing to file
Creating a Temporary File