[Fw:] Writing Big Files to servletOutputStream

xiaoxiao2021-03-06  83

Problem When Writing Big Files To ServletOutputStream

Transfer from:

http://www.theserverside.com/discussions/thread.tss?thread_id=29261

Posted by:

Anand Rajagopal on October 06, 2004 @ 10:18 AM

I am using the following code to write files to servlet output stream. The problem is the browser is not downloading the entire file when the file size grows above 10 MB. Any help would be greatly helpful.FileInputStream fis = new FileInputStream (new File ( fileName)); response.setHeader ( "Content-Disposition:", "attachment; filename =" fileName); BufferedInputStream bis = new BufferedInputStream (fis); ServletOutputStream sos = response.getOutputStream (); byte [] buffer = new byte [5000]; Response.setHeader ("Content-Length:", String.Valueof (bis.available ())); while (true) {int BytesRead = Bis.Read (buffer, 0, buffer.length); IF ( Break; sos.write (buffer, 0, bytesread);} fis.close (); sos.flush (); sos.close ();

Message # 141567

Mark As Noisy Mark As Noisy Mark As Noisy

Post reply post reply post reply

Go to Top Go to Top Go to Top Problem Wenn Writing Big Files To ServletOutputstream

Posted by:

Krishnan Muthusubramanian ON October 06, 2004 @ 11:45 AM in response to

Message # 141542

0 replies in this thread

Response.setHeader ("Content-Length:", String.Valueof (bis.available ()));

The 'Available' Method of InputStream Does NOT RETURN THE NUMBER OF BYTES That Avila :). Check The Java Doc for this method.try new file (filename) .length () Instead

转载请注明原文地址:https://www.9cbs.com/read-106151.html

New Post(0)