title: Using JSoup to save the contents of this url: http://www.aw20.co.uk/images/logo.png to a file
body: <p>I am try to use JSoup to get the contents of this url <a href="http://www.aw20.co.uk/images/logo.png" rel="nofollow">http://www.aw20.co.uk/images/logo.png</a>, which is the image logo.png, and save it to a file.  So far I have used JSoup to connect to <a href="http://www.aw20.co.uk" rel="nofollow">http://www.aw20.co.uk</a> and get a Document.  I then went and found the absolute url for the image I am looking for, but now am not sure how to this to get the actual image.  So I was hoping someone could point me in the right direction to do so?  Also is there anyway I could use Jsoup.connect("http://www.aw20.co.uk/images/logo.png").get(); to get the image?</p>
  
  <pre><code>import java.io.IOException;
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  import org.jsoup.select.Elements;
  
  
  public class JGet2 {
  
  public static void main(String[] args) {
  
      try {
          Document doc = Jsoup.connect("http://www.aw20.co.uk").get();
  
          Elements img = doc.getElementsByTag("img");
  
          for (Element element : img) {
              String src = element.absUrl("src");
  
              System.out.println("Image Found!");
              System.out.println("src attribute is: " + src);
              if (src.contains("logo.png") == true) {
                  System.out.println("Success");     
              }
              getImages(src);
          }
      } 
  
      catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  private static void getImages(String src) throws IOException {
  
      int indexName = src.lastIndexOf("/");
  
      if (indexName == src.length()) {
          src = src.substring(1, indexName);
      }
  
      indexName = src.lastIndexOf("/");
      String name = src.substring(indexName, src.length());
  
      System.out.println(name);
  }
  }
  </code></pre>