Download files for Java online. pdf

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.