亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問為何不這樣寫?

請問為何不這樣寫?

慕哥1240977 2016-07-30 20:44:05
下載一個圖片ban.jpg 別人的寫法: public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); response.setHeader("Content-Disposition",?"attachment;?filename=ban.jpg"); String?path=this.getServletContext().getRealPath("/image/ban.jpg"); FileInputStream?fis=new?FileInputStream(path); byte?buff[]=new?byte[1024]; int?len=0; OutputStream?os=response.getOutputStream(); while((len=fis.read(buff))>0){ os.write(buff,?0,?len);} os.close(); fis.close(); } 請問為何不這樣寫: public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); response.setHeader("Content-Disposition",?"attachment;?filename=ban.jpg"); String?path=this.getServletContext().getRealPath("/image/ban.jpg"); FileInputStream?fis=new?FileInputStream(path); byte?buff[]=new?byte[1024]; int?len=0; OutputStream?os=response.getOutputStream(); while((len=fis.read(buff))>0){ fis.read(buff);//這個地方 os.write(buff,?0,?len); } os.close(); fis.close(); }為何不寫這句?fis.read(buff);
查看完整描述

1 回答

?
Genment

TA貢獻43條經驗 獲得超25個贊

因為在while的條件那里已經寫了呀,再寫就重復了

查看完整回答
反對 回復 2016-07-31
  • 1 回答
  • 0 關注
  • 1217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號