java流下载

@RequestMapping("/pluginDownload")
public void pluginDownload(HttpServletResponse response) throws FileNotFoundException {
// 下载本地文件
String fileName = "plugin.rar";
// 读到流中
InputStream inStream = new FileInputStream("d:/up_pipegis/plugin/plugin.rar");
// 设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
// 循环取出流中的数据
byte[] b = new byte[128];
int len;
try {
while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
上一篇:CodeForce 7 B - Memory Manager(模拟)


下一篇:吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组