Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2003

Tip: Looking for answers? Try searching our database.

io

Thread view: 
IS - 27 Oct 2003 11:42 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.