package com.java.fengefu; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class A { public void aa(){ try { URL url = new URL("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490112942709&di=ba94365cbfb94370f9d4e4c2caffa6e1&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201606%2F27%2F20160627032356_FwKus.thumb.700_0.jpeg"); URLConnection openConnection = url.openConnection(); InputStream in = openConnection.getInputStream(); OutputStream out = new FileOutputStream("c:/888.jpg"); byte[] b = new byte[1024]; int c; while((c=in.read(b))!=-1){ out.write(b,0,c); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { A a = new A(); a.aa(); } }
时间: 2024-10-15 06:01:29