日期:2014-05-17 浏览次数:20789 次
。。。。。。。 byte[] buffer = new byte[SIZE]; byteread = bis.read(buffer); while (-1 != byteread) { System.out.println("count="+count++); System.out.println("aaaaaaa"); bos.write(buffer, 0, byteread); //A System.out.println("bbbbbbb"); byteread = bis.read(buffer); } bos.flush(); bos.close();
InputStream bis = null; OutputStream bos = null; try { ServletOutputStream sos = response.getOutputStream(); bis = new BufferedInputStream(new FileInputStream(filePath)); bos = new BufferedOutputStream(sos); byte[] buffer = new byte[4096]; // 清空response response.reset(); response.setContentType("application/octet-stream;charset=gbk"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); response.addHeader("Content-Length", "" + (int)new File(filePath).length()); response.flushBuffer(); response.setStatus(response.SC_OK); System.out.println("文件读取开始"); int byteread = 0; byteread = bis.read(buffer); while (-1 != byteread) { System.out.println("aaaaaaa"); bos.write(buffer, 0, byteread);//弹出下载框后,就会阻塞在这里 System.out.println("bbbbbbb"); byteread = bis.read(buffer); } bos.flush(); bos.close(); } catch (Exception e) { System.out.println("error:" + fileName); e.printStackTrace(); } finally { if (bis != null) { bis.close(); } if (bos != null) { bos.close(); } } System.out.println(fileName + "文件下载完毕.");