mybatis和ibatis控制台打印sql语句 http://blog.sina.com.cn/s/blog…
不静之心
分类:未分类
springmvc中获得HttpServletRequest request方法
springmvc中获得HttpServletRequest request方法 方法1: http://bl…
Spring整合velocity
Spring整合velocity 版本要1.4 , 1.6版本出现问题:Failed to load Dire…
生成java树对象
生成java树对象 http://javasl.blog.sohu.com/128841203.html 数据…
PostgreSQL的递归查询(with recursive)
PostgreSQL的递归查询(with recursive) http://my.oschina.net/K…
Spring扫描jar包中的类
Spring扫描jar包中的类转自: http://liuqiang5151.iteye.com/blog/1…
应用springMVC时 JS等文件找不到错误
应用springMVC时 JS等文件找不到错误 http://love-love-l.blog.163.com…
Spring 异常关键字 no matching editors or conversion strategy found 解决方法
Spring 异常关键字 no matching editors or conversion strategy…
tomcat ssl配置
tomcat ssl配置 http://my.oschina.net/internetafei/blog/39…
Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory
Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory http://…
windows下nginx+tomcat+memcached集群配置
windows下nginx+tomcat+memcached集群配置 http://my.oschina.ne…
postgreSQL存储过程写法示例
postgreSQL存储过程写法示例 PostgreSQL的存储过程简单入门 http://blog.csdn…
Web压力测试ApacheBench(ab), Boom简介
Web压力测试ApacheBench(ab), Boom简介 boom:go语言压力测试工具 apache a…
三种javascript数组搜索的效率对比
三种javascript数组搜索的效率对比 http://my.oschina.net/ZaneYoung/b…
Eclipse插件开发
Eclipse插件开发 Eclipse插件开发之基础篇(1) 插件开发的基础知识 http://www.360…
window.parent与window.opener的区别与使用
window.parent与window.opener的区别与使用 http://my.oschina.net…
java 两字符串相似度计算算法
java 两字符串相似度计算算法 http://itindex.net/detail/46929-java-%…
批量将PowerDesigner中表,字段,类型,序列由小写变成大写
批量将PowerDesigner中表,字段,类型,序列由小写变成大写 http://paskaa.iteye….
J2EE环境变量的其他使用方式
J2EE环境变量的其他使用方式 1. System.getProperty()获取tomcat自定义变量 ht…
BeanUtils beanjavaBean与Map互转
BeanUtils beanjavaBean与Map互转 [crayon-6a8041581629441346…
SQL的四种连接-左外连接、右外连接、内连接、全连接
SQL的四种连接-左外连接、右外连接、内连接、全连接 http://my.oschina.net/lichao…
WebWorker 语法糖 SugarWorker
WebWorker 语法糖 SugarWorker http://www.oschina.net/p/suga…
内存溢出之Tomcat内存配置
内存溢出之Tomcat内存配置 http://my.oschina.net/u/2291124/…
Windows 环境变量工具 Ev
Windows 环境变量工具 Ev http://www.oschina.net/p/evn Evn是Wind…
maven 常用命令
maven 常用命令 http://my.oschina.net/phacks/blog/387826 Mav…
SpringMVC文件上传接口设计与实现
SpringMVC文件上传接口设计与实现 http://my.oschina.net/pingpangkuan…
table合并单元格 colspan(跨列)和rowspan(跨行)
table合并单元格 colspan(跨列)和rowspan(跨行) http://blog.sina.com…
quartz定时器工具
quartz定时器工具 http://my.oschina.net/u/1261308/blog/386632…
jQuery使用iframe做tab标签
jQuery使用iframe做tab标签 jQuery Tab插件 http://jqueryui.com/t…
CSS 的优先级机制[总结]
CSS 的优先级机制[总结] http://www.cnblogs.com/xugang/archive/20…
CSS3 圆角边框
CSS3 圆角边框 http://www.w3school.com.cn/css3/css3_border.a…
HTML/CSS 超长题目自动省略的CSS
HTML/CSS 超长题目自动省略的CSS 超长标题自动省略的CSS [crayon-6a804158178a…
maven打包获得svn版本号
maven打包获得svn版本号 有两种方法; 1. 使用命令行, linux安装subversion, win…
Slik-Subversion使用命令行或者Ant获得本地svn的版本号码
Slik-Subversion使用命令行或者Ant获得本地svn的版本号码 使用命令行 Subversion …
Java下载网上图片
Java下载网上图片
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
package com.pandy.utils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; /** * 项目名称: wp_idea_linux * 功能说明: * 创建者: Pandy, * 邮箱: panyongzheng@163.com, 1453261799@qq.com * 版权: * 官网: * 创建日期: 15-2-2. * 创建时间: 下午3:11. * 修改历史: * ----------------------------------------------- */ public class DownloadImageFromHttp { public static void download(String url, String path) { InputStream in = null; try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); in = entity.getContent(); creareDir(path); File file = new File(path); FileOutputStream fout = new FileOutputStream(file); int l = -1; byte[] tmp = new byte[1024]; while ((l = in.read(tmp)) != -1) { fout.write(tmp, 0, l); } fout.flush(); fout.close(); }catch (Exception e){ e.printStackTrace(); } finally { try{ in.close(); }catch (Exception e){ } } } private static void creareDir(String filePath){ String dir = filePath.substring(0,filePath.lastIndexOf(File.separator)); File f = new File(dir); f.mkdirs(); } } |
