Java实现的预览功能

2016-12-15 14:32:00    admin    2089    原创

预览功能


File file = new File(System.getProperty("webapp.root") + valleyFile.getPath());
FileInputStream inputStream = new FileInputStream(file);
String download_filename = URLEncoder.encode(valleyFile.getFilename(), "UTF-8");//对文件名记性加密
response.reset();
response.setHeader("Content-Disposition", "attachment;filename=" + download_filename);
response.setContentType("application/octet-stream"); byte[] buffer = new byte[1024];
ServletOutputStream stream = response.getOutputStream(); 
boolean len = false; int len1;
 while((len1 = inputStream.read(buffer)) != -1) {
    stream.write(buffer, 0, len1);
}
inputStream.close();
stream.flush();
stream.close();


豫ICP备15006410号
蝉知 蝉知4.5.2