标签:ipa file类 tip 获取 except inpu 失败 NPU write
前端上传的文件流,在后台接口中通常是用MultipartFile类型的流格式接收
在某些情况下可能需要转为File类型的文件流再去处理
MultipartFile转File的实现方法
public File readFiles(MultipartFile file) { int n; File newFile = new File(file.getOriginalFilename()); try (InputStream in = file.getInputStream(); OutputStream os = new FileOutputStream(newFile)) { byte[] buffer = new byte[4096]; while ((n = in.read(buffer, 0, 4096)) != -1) { os.write(buffer, 0, n); } System.out.println("获取文件成功,暂存目录" + newFile.getAbsolutePath()); } catch (IOException e) { System.out.println("获取文件失败"); } return newFile; }
标签:ipa file类 tip 获取 except inpu 失败 NPU write
原文地址:https://www.cnblogs.com/baby123/p/12329355.html