By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

io

P: n/a
IS
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.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I don't know what your looking for, but this is how to copy files, ascii or
binary

import java.io.*;

String filename;

InputStreamReader in = new InputStreamReader(filename);
OutputStreamReaer out = new InputStreamReader(filename);

int i = 0;
boolean endNow = false;

while (!endNow)
{
i = in.read();
if (i == -1)
endNow = true;
else
out.write(i);
}

I dunno if thats what you want. But there it is anyway. Hope it helps.

Phillip Taylor

"IS" <fi*******@yahoo.com> wrote in message
news:bn**********@shiva.neobee.net...
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.

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2

P: n/a
SPG
I use the same but find this quicker..

int i=0;
byte[] bytes = new byte[32*1024];

while ( (i= in.read(bytes))!=-1 )
{
out.write(bytes);
}

I use a 32K byte array and read/ write in chunks.. Saves a lot of IO

Steve
"Phillip Taylor" <pr*******@hotmail.com> wrote in message
news:3f******@lungfunggdn.org...
I don't know what your looking for, but this is how to copy files, ascii or binary

import java.io.*;

String filename;

InputStreamReader in = new InputStreamReader(filename);
OutputStreamReaer out = new InputStreamReader(filename);

int i = 0;
boolean endNow = false;

while (!endNow)
{
i = in.read();
if (i == -1)
endNow = true;
else
out.write(i);
}

I dunno if thats what you want. But there it is anyway. Hope it helps.

Phillip Taylor

"IS" <fi*******@yahoo.com> wrote in message
news:bn**********@shiva.neobee.net...
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.

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #3

P: n/a
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

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.