使用org.jsoup.Jsoup下载网络中的图片
package com.enation.newtest;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jsoup.Connection;
import org.jsoup.Jsoup; public class JsoupTest { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String imageSrc = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png";
Connection.Response response = Jsoup.connect(imageSrc).execute();
byte[] img = response.bodyAsBytes();
System.out.println(img.length);
savaImage(img, "D:\\360Downloads", "test.png");
} public static void savaImage(byte[] img,String filePath,String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
File dir = new File(filePath);
try {
//判断文件目录是否存在
if(!dir.exists() && dir.isDirectory()){
dir.mkdir();
}
file = new File(filePath+"\\"+fileName);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(img);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(bos!=null){
try {
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} }
}
很方便的下载图片,学习一下
使用org.jsoup.Jsoup下载网络中的图片的更多相关文章
- 从网络中获取图片显示到Image控件并保存到磁盘
一.从网络中获取图片信息: /// <summary> /// 获取图片 /// </summary> /// <param name="url"&g ...
- Universal-Image-Loader解析(三)——用ListView和ViewPager加载网络中的图片
现在我们终于可以通过这个框架来实现ListView中加载图片了,至于ViewPager还是别的,原理其实都是一样的 一.ListView 1.布局文件 list_layout.xml & ...
- 『TensorFlow』生成式网络中的图片预处理
简介 这里的生成式网络是广义的生成式,不仅仅指gan网络,还有风格迁移中的类自编码器网络,以及语义分割中的类自编码器网络,因为遇到次数比较多,所以简单的记录一下. 背景 1.像素和数字 图像处理目标一 ...
- java开发在线下载功能,自动打开浏览器下载功能下载网络文件或图片
因为业务的需要,公司产品要求商品详情页面有个下载的功能 找了很多的方法,发现有的需要打开一个新窗口,而且在某些浏览器上不适用,所以继续寻找更好的方法 跟同事沟通后发现他那里有个下载的方法,不过是C#写 ...
- 基于正则表达式用requests下载网页中的图片
在慕课网看了正则表达式和requests的课程后,为了加深学习记忆,决定简单记录. 实现步骤: 1.先打开你要下载的网页,查看源码找出图片位置 2.编写正则匹配图片url 3.保存图片到本地 图文步骤 ...
- java读流方式,下载网络上的图片
本工具类支持url的list集合,具体实现如下所示: public static void download(ArrayList<String> listUrl, String downl ...
- js下载浏览器中的图片
jquery function download(src) { var $a = $("<a></a>").attr("href", s ...
- [转]java 下载网络上的图片并保存到本地目录
原文地址:http://takeme.iteye.com/blog/1683380 import java.io.File; import java.io.FileOutputStream; impo ...
- C# 网络编程之webBrowser获取网页url和下载网页中图片
该文章主要是通过C#网络编程的webBrowser获取网页中的url并简单的尝试瞎子啊网页中的图片,主要是为以后网络开发的基础学习.其中主要的通过应用程序结合网页知识.正则表达式实现浏览.获取url. ...
随机推荐
- 小游戏banner广告流量量主指引
小程序导航 https://wq.xmaht.top
- 深入理解restfulAPI和 Oauth2.0(精简版)
一.restfulAPI 1.解释: restfulAPI协议,我们也可以说是一套API接口编写风格. 它被现在很多企业所认可和默认,是一套成俗的API接口编写方案. 2.restfulAPI之资源 ...
- mysql_old_wrong
DELIMITER $ create trigger auto_post_person_pointafter insert on post for each rowbeginupdate person ...
- [Bzoj4408]神秘数(主席树)
Description 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数. 例如S={1,1,1,4,13}, 1 = 1 2 = 1+1 3 = 1+1+1 4 = 4 5 = ...
- TP-常见错误1
1.无法加载模块 FILE: D:\wamp64\www\www.test_shop.com\ThinkPHP\Library\Think\Dispatcher.class.php LINE: 178 ...
- Enhacing the content with JavaScript
What not to do : In theory , you could use JavaScript to add important content to a web page. Howev ...
- 6.定制10MINS首页1
原始代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- 我教你怎么玩转git
我教你怎么玩转git 1.想要练习解决冲突? 很好办.创建本地分支,a,b, a上面,这样改.b上面那样改. 然后你就解决冲突就可以了. 可以merge 或者cheerypick 2.想要玩一个不要历 ...
- Start with PJSIP on windows
To overcome the project of HD video conferencing systerm,I should learn to use the PJSIP. I should m ...
- CSS系列(6) CSS通配符详解
通配符使用星号*表示,意思是“所有的”. 平时使用电脑,比如要搜索C盘里所有的网页,可以使用 *.html来搜索,.html是网页的后缀名,*代表了所有网页的名称: 也就是使用 * 加后缀名,就可以在 ...