public class test { public static void main(String[] args) { ClassPathResource classPathResource = new ClassPathResource("/img"); try { InputStream inputStreamImg = classPathResource.getInputStream(); File[] fileList = classPathResource.getFile().listFiles(); for (int i = 0; i < fileList.length; i++) { File file = fileList[i]; InputStream inputStream = new FileInputStream(file); MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream); List<MultipartFile> list = new ArrayList<>(); list.add(multipartFile); System.out.println(file); } } catch (IOException e) { e.printStackTrace(); } } }
需要导入依赖:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-mock --> &