title: How to download file given url in java?
body: <p>I want to use file downloaded by this link in java ...</p>
  
  <p><a href="http://translate.google.com/translate_a/" rel="nofollow">http://translate.google.com/translate_a/</a>…</p>
  
  <p>If you click on above link you will get a file in json format. I want to get this file using java code.</p>
  
  <p>I tried this one</p>
  
  <pre><code>String word = "Moon";
  
  System.setProperty("http.proxyHost", "172.20.0.100");
  System.setProperty("http.proxyPort", "8080");
  
  URL url = new URL("http://translate.google.com/translate_a/t?client=t&amp;text="+word+"&amp;hl=en&amp;sl=en&amp;tl=hi&amp;ie=UTF-8&amp;oe=UTF-8&amp;multires=1&amp;otf=1&amp;ssel=3&amp;tsel=3&amp;sc=1");
  url.openConnection();
  InputStream reader = url.openStream();
  FileOutputStream writer = new FileOutputStream("t");
  byte[] buffer = new byte[153600];
  int bytesRead = 0;
  while ((bytesRead = reader.read(buffer)) &gt; 0)
  {  
      writer.write(buffer, 0, bytesRead);
      buffer = new byte[153600];
  }
  writer.close();
  reader.close();
  </code></pre>
  
  <p>Error </p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Server returned HTTP response code:  403 for URL: http://translate.google.com/translate_a/…
  at sun.net.www.protocol.http.HttpURLConnect…
  at java.net.URL.openStream(URL.java:1031)
  at smsMain.main(smsMain.java:19)
  </code></pre>
  
  <p>Direct download is working ( just click and see translation of word "Moon" in hindi ) but through program it is showing error !!!! why ???</p>
  
  <p>Please help in this regard .
  Thank you in advance !!!</p>