title: How to download a file from google drive using drive api java?
body: <p>I have tried some functions of Google drive, but I couldn't able to download the file from Drive.</p>
  
  <p>Here is the code which I used </p>
  
  <pre><code>private static InputStream downloadFile(Drive service, File file) {
      if (file.getDownloadUrl() != null &amp;&amp; file.getDownloadUrl().length() &gt; 0) {
        try {
          HttpResponse resp =
              service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
                  .execute();
          return resp.getContent();
        } catch (IOException e) {
          // An error occurred.
          e.printStackTrace();
          return null;
        }
      } else {
        // The file doesn't have any content stored on Drive.
        return null;
      }
    }
  </code></pre>
  
  <p>When I ran the script it shows <code>file.getDownloadUrl()</code> is NULL.</p>
  
  <p>What did I miss here?</p>
  
  <p>Now it's executing after adding the following line before I call the download function</p>
  
  <pre><code>File file1 = service.files().get(fileid).execute();
  downloadFile(service,file1);
  </code></pre>
  
  <p>Now the problem is how to download the file with the help of 'response' which I got from the script....</p>