0
我嘗試通過這種方式創建CommonsMultipartFile實例,但發生了java.lang.NullPointerException。如何創建CommonsMultipartFile實例
DiskFileItemFactory factory = new DiskFileItemFactory(1024*1024,null);
FileItem fileitem = factory.createItem("file", "application/vnd.ms-excel;charset=utf-8", true, "d:\\a.xls");//Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.commons.fileupload.disk.DiskFileItem.toString()
CommonsMultipartFile commonFile=new CommonsMultipartFile(fileitem);
你不應該自己創建它。你爲什麼需要這個? –
是的,我不應該自己創建它。而'java.lang.NullPointerException'的共振是沒有OutputStream獲取。「fileitem.getOutputStream();」解決問題。 – newCheng