1. 程式人生 > >從阿裏雲下載圖片到本地

從阿裏雲下載圖片到本地

out com read port cat found system ID method

下載圖片


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+"....."); }

從阿裏雲下載圖片到本地