当前位置:网站首页>Convert the file URL in the browser to a file stream
Convert the file URL in the browser to a file stream
2022-06-28 10:58:00 【Little doll】
/**
* Turn the picture into file
*
* @param url picture url
* @return File
* @author dyc
* date: 2020/9/4 14:54
*/
public File getFile(String url) throws Exception {
// Name local files
String fileName = url.substring(url.lastIndexOf("."),url.length());
File file = null;
URL urlfile;
InputStream inStream = null;
OutputStream os = null;
try {
file = File.createTempFile("net_url", fileName);
// download
urlfile = new URL(url);
inStream = urlfile.openStream();
os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != os) {
os.close();
}
if (null != inStream) {
inStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return file;
}
边栏推荐
- Xshell和Xftp使用教程
- Knowing the details of redis RDB, you can step on many holes less
- 实体转JSON时,值为null的字段的丢失问题
- soapui的菜鸟教程
- BigDecimal 类的 compareTo() 和 equals()方法
- Katalon当中的使用循环for、while和if...else、break、continue
- 使用API快捷创建ECS
- MySQL general binary installation method
- 还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!
- [monkey] Introduction to monkey test
猜你喜欢
![[monkey] Introduction to monkey test](/img/70/5a7152d0b6b77df7f9d6ad0e09e000.png)
[monkey] Introduction to monkey test

Fastposter v2.8.4 release e-commerce poster generator

如何利用k线图做技术分析

一种跳板机的实现思路

JS基础3

DlhSoft Kanban Library for WPF

An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!

JS foundation 1-js introduction and operator

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

Metersphere实现UI自动化元素不可点击(部分遮挡)
随机推荐
Makefile简介
MarkDown——基本使用语法
Threads and thread pools
Using loops for, while, and if in katalon else、break、continue
Summary of spatial temporal time series prediction modeling methods
[monkey] Introduction to monkey test
Metersphere uses JS to refresh the current page
Debug debugging in katalon
Understanding of FTP protocol
广州海关支持保障食品、农产品和中药材等民生物资稳定供港
Xshell和Xftp使用教程
如何利用k线图做技术分析
[QT] connect syntax reference implementation
How to use K-line diagram for technical analysis
树莓派无需显示屏的VNC Viewer方式的远程连接
无线模块透明传输技术的物联网应用案例
File的io流与base64
Mongo database
Katalon当中的debug调试
Metersphere implements UI automation elements that are not clickable (partially occluded)