第一種方法:
MultipartFile file = xxx; CommonsMultipartFile cf= (CommonsMultipartFile)file; DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
會(huì)在項(xiàng)目的根目錄的臨時(shí)文件夾下生成一個(gè)文件;
第二種方法:
transferTo(File dest);
會(huì)在項(xiàng)目中生成一個(gè)新文件;
第三種方法:
File f = (File) xxx 強(qiáng)轉(zhuǎn)即可。前提是要配置multipartResolver,要不然會(huì)報(bào)類型轉(zhuǎn)換失敗的異常。
    <bean id="multipartResolver" class="org.sPRingframework.web.multipart.commons.CommonsMultipartResolver">        <property name="maxUploadSize" value="104857600"/>        <property name="maxInMemorySize" value="4096"/>    </bean>  沒(méi)試過(guò);第四種方法:  Workbook wb = Workbook.getWorkbook(xxx .getInputStream());  轉(zhuǎn)換為輸入流,直接讀取;第五種方法:  byte[] buffer = myfile.getBytes();  先轉(zhuǎn)換為字節(jié)數(shù)組,沒(méi)試過(guò);| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注