当前位置:网站首页>Mutual conversion between mytipartfile and file
Mutual conversion between mytipartfile and file
2022-06-28 11:43:00 【Little doll】
1. MutipartFile Convert to File
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public File multipartFileToFile(MultipartFile file) throws Exception {
File toFile = null;
if (file.equals("") || file.getSize() <= 0) {
file = null;
} else {
InputStream ins = null;
ins = file.getInputStream();
toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
ins.close();
}
return toFile;
}
2. File Convert to MutipartFile
private static void inputStreamToFile(InputStream ins, File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}边栏推荐
- Graduation season, some suggestions for you who are new to the society
- This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
- TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
- Wireshark数据抓包分析之FTP协议
- Lihongyi, machine learning 7 Conclusion
- Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
- Get current system date
- Solutions to connection failures and errors when accessing mysql8 using the SSM project
- Simple understanding of ThreadLocal
- Packaging and publishing application of jetpack compose desktop version
猜你喜欢

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

day30 js笔记 BOM和DOM 2021.09.24

Cannot redeclare block range variables

零基础自学SQL课程 | IF函数

Redis6 一:Nosql引入、Redis可以解决什么问题?

水果FL Studio/Cubase/Studio one音乐宿主软件对比

科研丨Web of Science检索技巧

Making and using of dynamic library (shared library)

TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
随机推荐
The default point of this in JS and how to modify it to 2021.11.09
Dongyuhui, New Oriental and Phoenix Satellite TV
Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
Excel导入导出便捷工具类
【无标题】虚拟机vmnet0找不到且报错:没有未桥接的主机网络适配器
Calculate time using calendar
day34 js笔记 正则表达式 2021.09.29
Jetpack Compose Desktop 桌面版本的打包和发布应用
如临现场的视觉感染力,NBA决赛直播还能这样看?
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
Fancy features and cheap prices! What is the true strength of Changan's new SUV?
Unity屏幕截图功能
Timestamp and date conversion "suggested collection"
Blue Bridge Cup Maze (dfs+ backtracking)
Class pattern and syntax in JS 2021.11.10
Simulation of the Saier lottery to seek expectation
行业分析| 快对讲,楼宇对讲
Which broker is safer and more convenient to open an account for Oriental Fortune mobile stock?
Cannot redeclare block range variables
js中this的默认指向及如何修改指向 2021.11.09