Re: io
From: Raymond DeCampo (rdecampo_at_hold-the-spam.twcny.rr.com)
Date: 10/29/03
- Previous message: Hal Vaughan: "Re: How to set Permissions on New File"
- In reply to: IS: "io"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Oct 2003 01:30:02 GMT
IS wrote:
> Hi,
>
> I am new to java.io.* classes, and have a situation where I can't make a
> copy of my binary files. Txt are being copied with no trouble but when it
> comes to binaries i guess I am missing something since their structured is
> changed and are not read by an application correctry (Word, ACDSee etc.).
> At the moment, I have a JSP doing something like:
>
> response.setContentType("APPLICATION/OCTET-STREAM");
> response.setHeader("Content-Disposition", "attachment; filename=\"" +
> filename + "\"");
> java.io.FileInputStream fileInputStream = new
> java.io.FileInputStream(dbBean.getDataPath() + filename);
> int i;
> while ((i=fileInputStream.read()) != -1) {
> out.write(i); }
>
> Please advise of where I am making a mistake or what other class and how
> should I use.
JSPs are not suited for returning binary data. There is a technical
reason for this, the exact details escape me at the moment but the
upshot is that a JSP automatically starts using the output stream for
text. There was a tech tip from Sun that made the same mistake a while
back.
If you want to return binary data you should either use a servlet or
have your JSP create the response under a web server and forward the
request to it via the client.
Ray
- Previous message: Hal Vaughan: "Re: How to set Permissions on New File"
- In reply to: IS: "io"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|