java根据url下载图片

	public static void download(String _url,String path) throws Exception{
		try{  
		       URL url = new URL(_url);  
		       URLConnection con = url.openConnection();  
		       con.setConnectTimeout(5000);  
		       InputStream is = con.getInputStream(); 
		       byte[] bs = new byte[1024];   
		       int len;  
		      File sf=new File(path);  
		      OutputStream os = new FileOutputStream(sf);  
		       while ((len = is.read(bs)) != -1) {  
		         os.write(bs, 0, len);  
		       }   
		       os.close();  
		       is.close();  

		} catch (IOException e) {
		}        
		}

你可能感兴趣的:(java)