Upload the Download class below
The code is as follows |
Copy Code |
public static void DownloadFile (String fileName, String downloadname, httpservletresponse response) { try { Response.setcontenttype ("Octets/stream"); Response.AddHeader ("Content-type", "text/html; Charset=utf-8 "); String downloadname = new String (Downloadname.getbytes ("GBK"), "iso8859-1"); Response.AddHeader ("Content-disposition", "attachment;filename=" + downloadname); FileInputStream FileInputStream = new FileInputStream (fileName); OutputStream out = Response.getoutputstream (); int i = 0; while ((i = Fileinputstream.read ())!=-1) { Out.write (i); } Fileinputstream.close (); catch (Exception e) { E.printstacktrace (); } }
/** * Upload File * * @param file * File * @param radomfilename * Save file name * @param Materialfilepath * Save Path * @return */ public static Boolean FileUpload (Multipartfile file, String radomfilename, String Materialfilepath) { Boolean flag = true; File Basefile = new file (Materialfilepath); File Trainfile = new file (Basefile, radomfilename); if (!basefile.exists ()) { Basefile.mkdirs (); } try { File.transferto (Trainfile); catch (IllegalStateException e) { Flag = false; catch (IOException e) { Flag = false; }//Save File return flag; } |