当前位置:网站首页>MytipartFile与File的相互转换
MytipartFile与File的相互转换
2022-06-28 10:51:00 【小玩偶啊】
1. MutipartFile 转换为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转换为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();
}
}边栏推荐
- Ffmpeg audio and video recording
- Mysql database overview and installation process
- MarkDown——基本使用语法
- 广州海关支持保障食品、农产品和中药材等民生物资稳定供港
- Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
- How to use output in katalon
- 爱可可AI前沿推介(6.28)
- Sqlcmd database connection error
- Hystrix 部署
- AQS understanding
猜你喜欢

I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!

建立自己的网站(11)

港伦敦金行情走势图所隐藏的信息

一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!

Missed the golden three silver four, found a job for 4 months, interviewed 15 companies, and finally got 3 offers, ranking P7+

Idea failed to connect to SQL Sever

Yann LeCun新论文:构建自动智能体之路

Debug debugging in katalon

DlhSoft Kanban Library for WPF

fastposter v2.8.4 发布 电商海报生成器
随机推荐
知道 Redis RDB 这些细节,可以少踩很多坑
[unity] built in rendering pipeline to URP
JSON模块、hashlib、base64
Metersphere implements UI automation elements that are not clickable (partially occluded)
MySQL查看数据库性能常用命令
Hystrix 部署
请教下, 我在本地idea运行flinkcdc的mysql到mysql全量同步,这个是在我本地ide
Katalon framework tests web (XX) custom keywords and upload pop-up operations
一种跳板机的实现思路
To enhance the function of jupyter notebook, here are four tips
Information hidden in the trend chart of Hong Kong London gold market
Teach you how to handle the reverse SVG mapping of JS
Please consult me. I run the MYSQL to MySQL full synchronization of flykcdc in my local ide. This is in my local ide
Katalon当中的debug调试
flink1.15,支持mysql视图吗?我这边在table-name处配置视图名保存,找不到表。想
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
Six fusion positioning technologies in wireless communication application of Internet of things
各位大佬,问下Mysql不支持EARLIEST_OFFSET模式吗?Unsupported star
appliedzkp zkevm(9)中的Bytecode Proof
Who knows if it is safe to open an account with CSC securities