请问为何不这样写?

下载一个图片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);


慕哥1240977
浏览 1176回答 1
1回答

Genment

因为在while的条件那里已经写了呀,再写就重复了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java