A small problem with downloading a local file

Source: Internet
Author: User

Previous background method for downloading files

/**      * Download Attachment     * /public     voidthrows  ioexception        { = Getpara ("fjxxno");         = LkglService.service.fjxxDown (fjxxno);         byte [] Fjnr = Fjxx.get ("Fjnr");                 New toolfileconsole (). Loadfileforbyte (GetResponse (),        //The class is appended to the end of the text                string.valueof (fjxx.get ("FJMC" )), "Application/x-msdownload", Fjnr);    }

The attachment here is from the file that detects the database.

Change now: Need to download a local file (imitate above)

Background code;

private static String Downloadpath = "/files/aq/hj/jshjmb/jsmb.xlsx"; ()


/*** Download Attachments*/ Public voidDownload ()throwsIOException {String Realpath=Super. Getrealpath (); String Downloadpath= Realpath +Downloadpath; File File=NewFile (Downloadpath); System.out.println (File.exists ()); FileInputStream FIS=Newfileinputstream (file); Bytearrayoutputstream Bos=NewBytearrayoutputstream (); byte[] B =New byte[1024]; The array cannot be placed directly into the last parameter, or the file will not open. intLen; while(len = Fis.read (b))! =-1) {Bos.write (b,0, Len); } fis.close (); Bos.close (); byte[] buffer =Bos.tobytearray (); Newtoolfileconsole (). Loadfileforbyte (GetResponse (), string.valueof ("Family meeting Information template file. xlsx"), "Application/x-msdownload", buffer); //String.valueof ("Family Meeting Information template file. xlsx")Doesn't seem to be useful .
Rendernull (); }

Attention:

New Toolfileconsole (). Loadfileforbyte method The last parameter is a byte array

We take
Bytearrayoutputstream Bos read out the file.
Then byte[] buffer = bos.tobytearray ();  to a byte array format. Into the last parameter position.


A small problem with downloading a local file

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.