Guest User

Untitled

a guest
May 28th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. if (Files.exists(file)) {
  2. response.setContentType(existingDocuments.getContentType());
  3. response.addHeader("Content-Disposition", "attachment; filename=" + existingDocuments.getFileName());
  4. Files.copy(file, response.getOutputStream());
  5. response.getOutputStream().flush();
  6. }
  7.  
  8. String filePath=request.getParameter("filepath");
  9. File file=new File(filePath);
  10. response.setContentType("application/octet-stream");
  11. response.setHeader("Content-Disposition",
  12. "attachment;filename="+file.getName());
  13. InputStream is=new FileInputStream(file);
  14. int read=0;
  15. byte[] bytes = new byte[256];
  16. OutputStream os = response.getOutputStream();
  17. while((read = is.read(bytes))!= -1){
  18. os.write(bytes, 0, read);
  19. }
  20.  
  21. os.flush();
  22. is.close();
  23. os.close();
  24.  
  25. response.header("content-disposition", "attachment; filename="" + fileNameDisplay + """);
Add Comment
Please, Sign In to add comment