title: how download facebook profile picture in java in my computer disk
body: <p>I am using below code, its not working.<br/>
  when i use imageUrl on browser its redirect somewhere then its working.<br/>
  But i have n number of facebook id only and every time redirected url is different.</p>
  
  <pre><code>import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
   import java.net.URL;
  
  public class SaveImageFromUrl {
  
  public static void main(String[] args) throws Exception {
      String imageUrl = "http://graph.facebook.com/67563683055/picture?type=square";
      String destinationFile = "C:\\Users\\emtx\\Desktop\\Nxg-pic.png";
  
      saveImage(imageUrl, destinationFile);
  }
  
  public static void saveImage(String imageUrl, String destinationFile) throws IOException {
      URL url = new URL(imageUrl);
      InputStream is = url.openStream();
      OutputStream os = new FileOutputStream(destinationFile);
  
      byte[] b = new byte[2048];
      int length;
  
      while ((length = is.read(b)) != -1) {
          os.write(b, 0, length);
      }
  
      is.close();
      os.close();
  }
  </code></pre>
  
  <p>}</p>