title: Read error response body in Java
body: <p>In Java, this code throws an exception when the HTTP result is 404 range:</p>
  
  <pre><code>URL url = new URL("http://stackoverflow.com/asdf404notfound");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.getInputStream(); // throws!
  </code></pre>
  
  <p>In my case, I happen to know that the content is 404, but I'd still like to read the body of the response anyway.</p>
  
  <p>(In my actual case the response code is 403, but the body of the response explains the reason for rejection, and I'd like to display that to the user.)</p>
  
  <p>How can I access the response body?</p>