第一種方法:
MultipartFile file = xxx; CommonsMultipartFile cf= (CommonsMultipartFile)file; DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
會在項目的根目錄的臨時文件夾下生成一個文件;
第二種方法:
transferTo(File dest);
會在項目中生成一個新文件;
第三種方法:
File f = (File) xxx 強轉即可。前提是要配置multipartResolver,要不然會報類型轉換失敗的異常。
<bean id="multipartResolver" class="org.sPRingframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="104857600"/> <property name="maxInMemorySize" value="4096"/> </bean> 沒試過;第四種方法: Workbook wb = Workbook.getWorkbook(xxx .getInputStream()); 轉換為輸入流,直接讀取;第五種方法: byte[] buffer = myfile.getBytes(); 先轉換為字節數組,沒試過;新聞熱點
疑難解答