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.
Thanks!
I.S.
Chris - 08 Nov 2003 06:52 GMT
> Hi,
[snip]
> response.setContentType("APPLICATION/OCTET-STREAM");
> response.setHeader("Content-Disposition", "attachment; filename=\""
[quoted text clipped - 9 lines]
> Thanks!
> I.S.
Hello,
You can't transmit binary data in a JSP. By the time your JSP code
starts running, the object "out" has already been created. "out" is a
text based class, specifically some type of Writer (not sure exactly
what), meaning it can transmit text as characters but not data as
bytes. What you need is an OutputStream. The only way you'll get an
OutputStream is to use a servlet, where you can choose whether to
open an OutputStream or a Writer to send your output to.
- --
Chris