InputStream is = new FileInputStream(filePath); byte[] b = new byte[8 * 1024];
int length = -1;
OutputStream out = response.getOutputStream();
while ((length = is.read(b)) != -1) {
out.write(b, 0, length);
}
out.close();
is.close();1:里面为什么length=-1 等于其他不行么?
2:可以这样写吗:
int length=is.read(b);
while(length!=-1){
..............................
}
5 回答

繁星淼淼
TA贡献1775条经验 获得超11个赞
你的is应该是文件流吧,InputStream is = new FileInputStream(“。。。”);应该这么写的对吧,然后每次最多读入的字节就是8*1024,然后等文件读完就会返回-1。意思就是每次从一个文件度8*1024字节,然后一直循环把文件读完
添加回答
举报
0/150
提交
取消