You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by jsona laio <fr...@yahoo.co.uk> on 2004/12/06 06:38:38 UTC

save file problem

Hi,
Lately I write a simple program follow up the sample
code on http client
(http://jakarta.apache.org/commons/httpclient/tutorial.html).
I want to save a file after gettin the content from
the web (an zip file format), which associate with an
inputStream (with post method getResponseBody() ).
But I encounter a problem when compiling source code.
What should I do in order to save a file correctly? Or
where there's resource talking about this.
I appreciate it sincerely.
Jason.

============BEG=============
HttpClientTutorial.java:47:
ObjectOutputStream(java.io.OutputStream) in java.io.
ObjectOutputStream cannot be applied to ()
ObjectOutputStream out = new ObjectOutputStream() ;
^
============END=============
=========beg save file snippet source====
byte[] bytes = new byte[10240];
ObjectInputStream ois = new ObjectInputStream(in);
ObjectOutputStream out = new ObjectOutputStream() ;
int beg = 0;
int len = 0;
long c =0;
while(ois.read(bytes)!=-1){
out.write(bytes, beg , 10240);
beg += 10240;
}
ois.close();
out.close();
=========end save file snippet source====


		
___________________________________________________________ 
Win a castle for NYE with your mates and Yahoo! Messenger 
http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Re: save file problem

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Jason,

unless you want to save serialized Java objects, the
ObjectOutputStream is not a good choice. The reason
why the compiler complains is that you are not
providing an OutputStream where the objects could
be saved. The no-args constructor is only for people
that re-implement ObjectOutputStream.

Try to replace ObjectOutputStream with FileOutputStream.
Drop the ObjectInputStream completely, use the stream
you get from getResponseBodyAsStream().

cheers,
  Roland





jsona laio <fr...@yahoo.co.uk> 
06.12.2004 06:38
Please respond to
"HttpClient Project"


To
httpclient-dev@jakarta.apache.org
cc

Subject
save file problem






Hi,
Lately I write a simple program follow up the sample
code on http client
(http://jakarta.apache.org/commons/httpclient/tutorial.html).
I want to save a file after gettin the content from
the web (an zip file format), which associate with an
inputStream (with post method getResponseBody() ).
But I encounter a problem when compiling source code.
What should I do in order to save a file correctly? Or
where there's resource talking about this.
I appreciate it sincerely.
Jason.

============BEG=============
HttpClientTutorial.java:47:
ObjectOutputStream(java.io.OutputStream) in java.io.
ObjectOutputStream cannot be applied to ()
ObjectOutputStream out = new ObjectOutputStream() ;
^
============END=============
=========beg save file snippet source====
byte[] bytes = new byte[10240];
ObjectInputStream ois = new ObjectInputStream(in);
ObjectOutputStream out = new ObjectOutputStream() ;
int beg = 0;
int len = 0;
long c =0;
while(ois.read(bytes)!=-1){
out.write(bytes, beg , 10240);
beg += 10240;
}
ois.close();
out.close();
=========end save file snippet source====


 
___________________________________________________________ 
Win a castle for NYE with your mates and Yahoo! Messenger 
http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org