spring MVC 的MultipartFile轉File讀取

第一種方法:java

     MultipartFile file = xxx; 
        CommonsMultipartFile cf= (CommonsMultipartFile)file; 
        DiskFileItem fi = (DiskFileItem)cf.getFileItem(); web

        File f = fi.getStoreLocation();spring

  會在項目的根目錄的臨時文件夾下生成一個文件;數組

第二種方法:spa

    transferTo(File dest);code

  會在項目中生成一個新文件;ip

第三種方法:   get

  File f = (File) xxx 強轉便可。前提是要配置multipartResolver,要否則會報類型轉換失敗的異常。string

    <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();
  先轉換爲字節數組,沒試過;
相關文章
相關標籤/搜索