BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
String filepath=path;//本地绝对路径
File uploadFile = new File(filepath);
fis = new FileInputStream(uploadFile);
bis = new BufferedInputStream(fis);
reponse.reset();
fos = reponse.getOutputStream();
bos = new BufferedOutputStream(fos);
reponse.setContentType("text/plain");
reponse.setHeader("Content-disposition","attachment; filename="+uploadFile.getName());
int bytesRead = 0;
//用输入流进行先读,然后用输出流去写,唯一不同的是我用的是缓冲输入输出流
// byte[] buffer = new byte[8192];
// while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
// bos.write(buffer, 0, bytesRead);
// }
FileCopyUtils.copy(fis, bos);//spring工具类直接流拷贝
bos.flush();
fis.close();
bis.close();
fos.close();
bos.close();
这个功能IE,firef是好的 但是在360下载时候 我分析是直接下载了ACTION
直接输出流到360,360有个下载管理工具来识别这个请求的文件名之类的信息.然后需要点击确定后(此后会再次请求一次刚才的地址),才会具体把这个输出的东西保存为具体文件.这个时候就把action下载出来了(可能这个地方说ACTION有些歧义)
这里请求了两次那个文件.
把360下载换成IE(工具-》下载器-》设置-》默认下载工具为IE).这个问题就解决了