ServletOutputStream out = response.getOutputStream(); ba.writeTo(out); out.flush();
In this case, ba is actually a ByteArrayOutputStream, so you'll have to figure out the proper cast/wrapping for your case. Actually, if the file you are trying to return is in-memory, then it shouldn't be a big deal. If it's on the file system, just open the file and get a stream off it, then write it out to OUT above (diid that make sense??)
Frank
From: "Miquel Angel" <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Subject: Downloading a file from an Action class. Date: Thu, 10 Jun 2004 14:01:05 +0200
Hi!
I try to download a file from an action class to the user PC. That's what I
do in the action class:
String Path = "C:" + java.io.File.separator; //Location of the file String FileName = Path + "CSV.TXT"; //Name of the file int buffer = 10 * 1024; File file = new File(FileName); FileOutputStream fos = new FileOutputStream(file);
//Fill the file with some information. PrintWriter pw = new PrintWriter(fos); for (int i = 0; i< 200; i++) { pw.write("l1 campo1" + ";" + "l1 campo2" + ";" + "l1 campo3" + "\n"); pw.write("l2 campo1" + ";" + "l2 campo2" + ";" + "l2 campo3" + "\n"); }
pw.flush(); pw.close();
fos.close();
//download response.reset(); response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); response.flushBuffer();
return null;
All works fine, but when the user save the file, it's empty. Any ideas..
Thanks in advance.
Miquel Angel Segui
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]