Here I want to say the point is: this method File.transferto (newFile), do not have to go to hand-written file upload, directly with this method can
Here is the JSP
<formname= "Form2"Action= "/springmvc006/fileupload2"Method= "POST"enctype= "Multipart/form-data"><H1>Upload files using the File.transfer method provided by multipart</H1><inputtype= "File"name= "File"><inputtype= "Submit"value= "Upload"/></form>
Note This annotation @RequestParam ("file") .
@RequestMapping ("FileUpload2") PublicString FileUpload2 (@RequestParam ("file")Commonsmultipartfile file)throwsIOException {LongStarttime=System.currenttimemillis (); System.out.println ("FileName:" +file.getoriginalfilename ()); String Path= "e:/" +NewDate (). GetTime () +File.getoriginalfilename (); File NewFile=NewFile (path); //write the file directly by Commonsmultipartfile (note this time)File.transferto (NewFile); LongEndtime=System.currenttimemillis (); System.out.println ("Method two run Time:" +string.valueof (endtime-starttime) + "MS"); return"/success"; }
[Technology Sharing]20171229_spring MVC _ Spring MVC file Upload