从阿里云下载图片到本地
生活随笔
收集整理的這篇文章主要介紹了
从阿里云下载图片到本地
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載圖片
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+".....");}
?
轉載于:https://www.cnblogs.com/dztHome/p/8890954.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的从阿里云下载图片到本地的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML-参考手册: HTTP 方法:G
- 下一篇: Python常用模块——目录