java根据url下载附件源码
发布日期:2021-10-03 01:52:11 浏览次数:10 分类:技术文章

本文共 766 字,大约阅读时间需要 2 分钟。

public static void runDownLoad(String title,String fileurl,String filename){
// 构造URL
URL url;
try {
url = new URL(fileurl);
// 打开URL连接
URLConnection con = (URLConnection)url.openConnection();
// 得到URL的输入流
InputStream input = con.getInputStream();
// 设置数据缓冲
byte[] bs = new byte[1024 * 2];
// 读取到的数据长度
int len;
// 输出的文件流保存图片至本地
String path1 = "c:/aa/"+title;
File f = new File(path1);
f.mkdirs();
// String hzm=fileurl.split("\\.")[fileurl.split("\\.").length-1];
OutputStream os = new FileOutputStream(path1+"\\"+filename);
while ((len = input.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
input.close();
} catch (MalformedURLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}

转载地址:https://blog.csdn.net/kai402458953/article/details/88340442 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:oracle数据库sql练习
下一篇:oracle数据处理sql

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月07日 03时02分50秒