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