//创建链接 URL url = new URL("http://api.map.baidu.com/images/weather/day/xiaoyu.png"); //打开链接 URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); InputStream is = conn.getInputStream(); byte[] bs = new byte[1024]; int len; File f = new File("d:/"); if(!f.exists()){ f.mkdir(); } OutputStream os = new FileOutputStream(f.getPath()+"\"+ UUID.randomUUID() + ".png"); while((len = is.read(bs)) != -1){ os.write(bs, 0, len); } is.close(); os.close();