简单图片抓取,Java实现
简单实例,保存时可修改格式。
阅读(32) | 评论(0) | 转发(0) |
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
点击(此处)折叠或打开
- public void getpic(String src,String num,int loc,String alt,String category,String name) {
- int id = Integer.parseInt(num);
- int id1 = id/1000000;
- int id2 = id/1000;
- String path ="F:\\image\\"+id1+"\\"+id2+"\\"+num+"\\";
- File cate = new File(path);
- if (!cate.exists()&&!cate.isDirectory()) {
- cate.mkdirs();
- }
- String target = path+loc+".png";
- File file = new File(target);
- //System.out.println("url "+src);
-
- //System.out.println(target);
-
- try {
- URL url = new URL(src);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- InputStream inputStream=httpURLConnection.getInputStream();
- byte[] bs = new byte[1024];
- int len;
- OutputStream outputStream = new FileOutputStream(file, true);
- while ((len=inputStream.read(bs))!=-1) {
- outputStream.write(bs, 0, len);
- }
- outputStream.close();
- inputStream.close();
- httpURLConnection.disconnect();
- BufferedImage bufferedImage = ImageIO.read(file);
- int width = bufferedImage.getWidth();
- int height = bufferedImage.getHeight();
- } catch (Exception e) {
- // TODO: handle exception
-
- //e.printStackTrace();
-
- return ;
- }
- }
简单实例,保存时可修改格式。
相关热门文章
- 欢迎弈天蝎在ChinaUnix博客安...
- 欢迎572745975在ChinaUnix博客...
- 开网店卖什么好——决议网店是...
- 怎么应用搜寻引擎推广你的店肆...
- 欢迎baimaa6vw1在ChinaUnix博...
给主人留下些什么吧!~~
评论热议