wms's Programming&Study

[JAVA] File을 MultipartFile로 변환 본문

Programming/JAVA

[JAVA] File을 MultipartFile로 변환

wms2275 2019. 9. 18. 23:23

File file = new File("C:\\Users\\lje\\Desktop\\test.xlsx");
DiskFileItem fileItem = new DiskFileItem("file", Files.probeContentType(file.toPath()), false, file.getName(), (int) file.length() , file.getParentFile());
	       
InputStream input = new FileInputStream(file);
OutputStream os = fileItem.getOutputStream();
IOUtils.copy(input, os);
	        
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);