title: How to wait for the HTTP request to get completed in java
body: <p>I am writing Java code where i am downloading the file from a server and i have to copy the file in my local system when the file download is complete.</p>
  
  <p>I am using the below code:-</p>
  
  <pre><code>OkHttpClient.Builder builder = new OkHttpClient.Builder();
          OkHttpClient client = builder.readTimeout(600, TimeUnit.SECONDS).writeTimeout(600, TimeUnit.SECONDS)
                  .connectTimeout(600, TimeUnit.SECONDS).build();
          Request downloadRequest = new Request.Builder().url(url + fileName).addHeader("cache-control", "no-cache")
                  .addHeader("Authorization", token).build();
          try {
              Response downloadResponse = client.newCall(downloadRequest).execute();
              System.out.println(downloadResponse.message());
              System.out.println("got response from blob " + downloadResponse.isSuccessful() + " " + fileName);
              return downloadResponse;
          } catch (IOException e1) {
              e1.printStackTrace();
          }
      return null;
  </code></pre>
  
  <p>}</p>
  
  <p>But the request is made asynchronously and before the request is completed then response is returned which is incomplete. Can anyone please help me how can i make a request and wait till the response is completed.</p>
  
  <p>Any help is highly appreciated!</p>