hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ROLWE...@de.ibm.com>
Subject Re: save file problem
Date Mon, 06 Dec 2004 07:09:47 GMT
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 <freeonfair@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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message