Good website Ortwin......keep it up....thanks -----Original Message----- From: Ortwin Glück [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 28, 2006 11:12 AM To: HttpClient Project Subject: Re: Hi ... httpclient for PDF files ???
Vijay, It's wrong to use a DataInputStream this way. DataInputStream is for serialized Java objects! A typical beginner's mistake I should put in my list of anti-patterns: http://www.odi.ch/prog/design/newbies.php The correct way to copy a byte stream to disk is: InputStream in = new BufferedInputStream(responseBodyStream); FileOutputStream fos = new FileOutputStream("rwservlet.pdf"); byte[] buffer = new byte[4098]; int len = 0; while ((len = in.read(buffer) > 0) { fos.write(buffer, 0, len); } Cheers Ortwin Vijay Gomatam wrote: > DataInputStream data = new DataInputStream(new > BufferedInputStream(responseBodyStream)); > FileOutputStream fos = new FileOutputStream("rwservlet.pdf"); > > *while* ((c =data.read(b)) != -1){ > > *byte*[] inter=*new* *byte*[c]; > > *for*(*int* i=0;i<c;i++) inter[i]=b[i]; > > fos.write(inter); > > } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
