当前位置:网站首页>IO stream of file and Base64
IO stream of file and Base64
2022-06-28 11:43:00 【Little doll】
1.file Convert to base64 character string
@Value("${file.store.path}\\")
private String path;
/**
* Change the file base64 code
* @param file
* @return
*/
public String FileToBase64(File file){
String base64 = null;
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
System.out.println(base64);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BASE64Encoder encoder = new BASE64Encoder();
String result=encoder.encode(data);
return result;
}
2. base64 String conversion to file Of io flow , And write local , Returns the size of the file
/**
* take base64 Convert to file and write locally
*/
public long base64ToFile(String base64Str,String filePath,String fileName) {
long fileSize=0;
if (base64Str == null && filePath == null) {
return 0;
}
try {
filePath=path+filePath;
File file = new File(fileName);
File dir = new File(filePath);
if (!dir.exists()) {
dir.mkdirs();
}
if(!file.exists()){
file.createNewFile();
}
filePath=filePath+"\\"+"_"+fileName;
Files.write(Paths.get(filePath), Base64.getMimeDecoder().decode(base64Str), StandardOpenOption.CREATE);
File imageFile = new File(filePath);
fileSize = FileUtils.sizeOf(imageFile);
} catch (IOException e) {
e.printStackTrace();
}
return fileSize;
}边栏推荐
- Day39 prototype chain and page Fireworks Effect 2021.10.13
- Timestamp and date conversion "suggested collection"
- recent developments
- The default point of this in JS and how to modify it to 2021.11.09
- Redis6 一:Nosql引入、Redis可以解决什么问题?
- ProCAST有限元铸造工艺模拟软件
- It is safer for individuals to choose which securities company to open an account for buying floor funds
- Excel导入导出便捷工具类
- What is the main chain system?
- 一套十万级TPS的IM综合消息系统的架构实践与思考
猜你喜欢

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性

Day36 JS notes ecma6 syntax 2021.10.09

Day37 JS note motion function 2021.10.11

day31 js笔记 DOM下 2021.09.26

Jetpack Compose Desktop 桌面版本的打包和发布应用

Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community

js中this的默认指向及如何修改指向 2021.11.09

网页提示此站点不安全解决方案

Get current system date
随机推荐
TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
Day39 prototype chain and page Fireworks Effect 2021.10.13
On the output representation of bidirectional LSTM in pytoch
day39 原型鏈及頁面烟花效果 2021.10.13
Day39 prototype chain and page fireworks effect 2021.10.13
day32 js笔记 事件(上)2021.09.27
关于Pytorch中双向LSTM的输出表示问题
Class pattern and syntax in JS 2021.11.10
Making and using of dynamic library (shared library)
Simulation of the Saier lottery to seek expectation
Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
Jetpack Compose Desktop 桌面版本的打包和发布应用
Unity screenshot function
Day24 JS notes 2021.09.15
SQL必需掌握的100个重要知识点:检索数据
day31 js笔记 DOM下 2021.09.26
day34 js笔记 正则表达式 2021.09.29
[no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
第2章 还记得点、线、面吗(二)
[sciter]: use of sciter FS module scanning file API and its details