Download files for Java online. pdf
1. Download the local location of the resource
2. Setting the response header
3. Download the Code
1 Periodicalresource Periodicalresource =periodicalresourceservice.get (ID);2String FilePath =periodicalresource.getattachment ();//Get Resource location3 File File = new file (Periodicalbasedir + FilePath);//local source location4 if(File.exists ()) {5 Response.setcontenttype ("Application/force-download");//set force download does not open6Response.AddHeader ("Content-disposition",7"Attachment;filename=" + filepath.split ("/") [Filepath.split ("/"). Length-1]);//Set file name8 byte[] buffer =New byte[1024];9FileInputStream FIS =NULL;TenBufferedinputstream bis =NULL; One Try { AFIS =Newfileinputstream (file); -bis =NewBufferedinputstream (FIS); -OutputStream OS =Response.getoutputstream (); the inti =bis.read (buffer); - while(I! =-1) { -Os.write (buffer, 0, i); -i =bis.read (buffer); + } -}Catch(Exception e) { + e.printstacktrace (); A}finally { at if(bis! =NULL) { - Try { - bis.close (); -}Catch(IOException e) { - e.printstacktrace (); - } in } - if(FIS! =NULL) { to Try { + fis.close (); -}Catch(IOException e) { the e.printstacktrace (); * } $ }Panax Notoginseng } -}
I didn't do it online. Now the project is used to let the great God sent a code look at their own research
Download files for Java online. pdf