Hi, Siddharth,
I think the cast to (char) is probably corrupting your image download. Images
are binaries, so it's best to treat them as bytes and not chars.
I recommend using the (usually) higher performing read( byte[] ) and write(
byte[] ) methods of InputStream and OutputStream.
FileOutputStream out = null;
try
{
out = new FileOutputStream( "/downloads/image.jpg" );
byte[] buf = new byte[ 4096 ];
int r = in.read( buf );
while ( r >= 0 )
{
if ( r > 0 )
{
out.write( buf, 0, r );
}
r = in.read( buf );
}
}
finally
{
try { if ( out != null ) out.close(); } catch ( IOException ioe ) {}
}
yours,
Julius
-----Original Message-----
From: Siddharth Godbole [mailto:[EMAIL PROTECTED]
Sent: Sun 7/16/2006 9:52 AM
To: HttpClient List
Cc:
Subject: Getting Images from the http server
Hi,
I wanted to know about how i can get images from the server. Right now the
method i used was like this:
1. Create a GET method for the image and Execute it.
2. Get its input stream
3. Use while loop as follows:
while((web_data = in.read()) != -1) {
dataFile.writeOneChar((char)web_data);
}
4. And then close the file and the connection.
But this is not working. Please can anyone tell me how can i achieve this ?
Regards,
Sid
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]