码迷,mamicode.com
首页 > 其他好文 > 详细

从阿里云下载图片到本地

时间:2018-04-20 16:08:04      阅读:1985      评论:0      收藏:0      [点我收藏+]

标签:AC   generate   exce   http   catch   style   NPU   sys   last   

下载图片


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;


public
static void main(String[] args) { // TODO Auto-generated method stub
    //图片线上地址:xxx
File file1=new File("xxx"); String name = file1.getName(); File file2=new File("F:\\bbb\\"+name);//本地地址 try { URL url = new URL("https://hlww.oss-cn-shanghai.aliyuncs.com/hlww/pic/img_32_1521892791.jpeg "); BufferedInputStream in = new BufferedInputStream(url.openStream()); FileOutputStream out = new FileOutputStream(file2); int t; while ((t = in.read()) != -1) { out.write(t); } out.close(); in.close(); System.out.println("图片获取成功"); }catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("fileName:"+name); String prefix1=name.substring(name.lastIndexOf(".")); System.out.println(prefix1+"....."); }

 

从阿里云下载图片到本地

标签:AC   generate   exce   http   catch   style   NPU   sys   last   

原文地址:https://www.cnblogs.com/dztHome/p/8890954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!