• 从阿里云下载图片到本地


    下载图片

    
    

    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+"....."); }
  • 相关阅读:
    [USACO 5.5]Hidden Password
    [Codeforces 1016F]Road Projects
    再会,OI
    [TJOI 2018]智力竞赛
    [POI 2009]Lyz
    [NOI 2015]品酒大会
    [NOI 2017]蔬菜
    [NOI 2017]整数
    [NOI 2017]游戏
    [NOI 2017]蚯蚓排队
  • 原文地址:https://www.cnblogs.com/dztHome/p/8890954.html
Copyright © 2020-2023  润新知