Hi Julius,

  Thaks for your advice. That things works very well.

Regards,
Sid
----- Original Message ----- From: "Julius Davies" <[EMAIL PROTECTED]> To: "HttpClient User Discussion" <[email protected]>; "HttpClient List" <[email protected]>
Sent: Monday, July 17, 2006 2:15 AM
Subject: RE: Getting Images from the http server


***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********


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]




--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 7/14/2006



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to