java下载web图片

String url = "http://www.google.com.hk/logos/2010/stevenson10-hp.jpg";

  HttpClient client = new HttpClient();
  GetMethod get = new GetMethod(url);
  try {
   client.executeMethod(get);
   File storeFile = new File("d:/1.jpg");
   FileOutputStream fileOutputStream = new FileOutputStream(storeFile);
   FileOutputStream output = fileOutputStream;
   output.write(get.getResponseBody());
   output.close();
  } catch (HttpException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

你可能感兴趣的:(java,Web,Google,HP)