首页 > 其他分享 >根据图片地址下载图片到本地

根据图片地址下载图片到本地

时间:2022-09-21 15:01:04浏览次数:69  
标签:String buffer length 地址 dataInputStream fileOutputStream 本地 new 图片

   public static void main(String[] args) {
        String urls = "http://rongcloud-web.qiniudn.com/docs_demo_rongcloud_logo.png";
        String path = "d:/pic.png";
        try {
            URL url = new URL(urls);
            DataInputStream dataInputStream = new DataInputStream(url.openStream());
            FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
            ByteArrayOutputStream output = new ByteArrayOutputStream();

            byte[] buffer = new byte[1024];
            int length;

            while ((length = dataInputStream.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
            fileOutputStream.write(output.toByteArray());
            dataInputStream.close();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

标签:String,buffer,length,地址,dataInputStream,fileOutputStream,本地,new,图片
From: https://www.cnblogs.com/ckfeng/p/16715539.html

相关文章

  • 前端怎么对一张图片特定某些点进行点击事件(image-map)
    图片热区技术插入一张图片,并设置好图像的有关参数,在<img>标记中设置参数usemap="#image-map",以表示对图像地图的引用。用<map>标记设定图像地图的作用区域,并取名:image-ma......
  • FCKEditor粘贴word图片问题解决
    ​ 当前功能基于PHP,其它语言流程大致相同 1.新增上传wordjson配置在ueditor\php\config.json中新增如下配置:     /* 上传word配置 */    "wordAction......
  • 个人解决Typora+PicGo+Gitee图片403 Forbidden报错
    个人解决Typora+PicGo+Gitee图片403Forbidden报错在使用Typora+picgo+gitee时一直上传失败,显示报错403...参考其他文章解决检查路径命名错误,以及server更改等问题......
  • 如何查看 计算机名 和 有线网物理地址
     计算机名查看方法:cmd-->ipconfig/all-->“WindowsIP配置”下的主机名 有线网物理地址查看方法:cmd-->ipconfig/all-->“以太网适配器以太网”下的物理地址(例如......
  • vue下载图片
       asyncworks(obj){   awaitthis.axios({    method:'get',    url:`entryFormController/downloadWork.do`,    param......
  • vue多图片上传组件
         <template><!--上传控件用法:<upload-widgetv-model="imgUrl"></upload-widget>--><divclass="clearfix"><a-upload......
  • 删除远程桌面链接下拉框ip地址
    一、介绍如下图,远程桌面连接会将我们以前连接过的主机IP地址都记录在这个下拉框里,为了某些原因我们可能需要删除这些记录!【请先阅读“三、备注”后操作】二、操作步骤......
  • WPF 使用 Win10 的 WinRT 自带 Windows.Media.Ocr 实现图片转文本
    世界上有很多OCR识别技术,本文来和大家介绍如果在WPF里,在运行到win10的设备上,通过WindowsRuntime自带的Windows.Media.Ocr实现在给定的图片里面识别文本的功能......
  • 去除图片水印
    带水印的图片:   #-*-coding:utf-8-*-fromPILimportImageprint('程序进行中...')#img=Image.open('../file/带水印的图片.png')img=Image.open('......
  • Kafka本地单实例安装
    下载安装从国内镜像站点下载并安装Kafka安装包,以下载并安装v3.2.3版本为例。$tar-xzfkafka_2.12-3.2.3.tgz$cdkafka_2.12-3.2.3启动服务如下命令均在Kafka安装......