日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

[FW:] Writing big files to ServletOutputStre

系統 1897 0

Problem when writing big files to ServletOutputStream

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 (bytesRead < 0)
break;
sos.write(buffer, 0, bytesRead);
}
fis.close();
sos.flush();
sos.close();

<!-- <form class="userinput"> <div class="center"><button type="submit" onmouseover="this.className='over'" onmouseout="this.className='';" onmousedown="this.className='down'">Post reply</button></div> </form> -->
<!-- header -->
<!-- info --> Message #141567 <!-- button --> Mark as noisy Mark as noisy Mark as noisy <!-- button --> Post reply Post reply Post reply <!-- button --> Go to top Go to top Go to top

Problem when 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 avilable :). Check the Java Doc for this method.

Try new File(fileName).length() instead

[FW:] Writing big files to ServletOutputStream


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 曲水县| 通江县| 明光市| 黄龙县| 克山县| 延吉市| 读书| 嘉鱼县| 巴楚县| 濮阳市| 沅陵县| 东方市| 鞍山市| 和田市| 名山县| 崇礼县| 奉化市| 林甸县| 华池县| 文昌市| 托克逊县| 永修县| 额尔古纳市| 昌黎县| 开江县| 万安县| 博白县| 车致| 桦甸市| 姜堰市| 大冶市| 莒南县| 海丰县| 京山县| 三门峡市| 新野县| 乌拉特后旗| 馆陶县| 开平市| 五原县| 泾川县|