title: HTTP URL Address Encoding in Java
body: <p>My Java standalone application gets a URL (which points to a file) from the user and I need to hit it and download it. The problem I am facing is that I am not able to encode the HTTP URL address properly...</p>
  
  <p>Example: </p>
  
  <pre><code>URL:  http://search.barnesandnoble.com/booksearch/first book.pdf
  
  java.net.URLEncoder.encode(url.toString(), "ISO-8859-1");
  </code></pre>
  
  <p>returns me:</p>
  
  <pre><code>http%3A%2F%2Fsearch.barnesandnoble.com%2Fbooksearch%2Ffirst+book.pdf
  </code></pre>
  
  <p>But, what I want is</p>
  
  <pre><code>http://search.barnesandnoble.com/booksearch/first%20book.pdf
  </code></pre>
  
  <p>(space replaced by %20)</p>
  
  <p>I guess <code>URLEncoder</code> is not designed to encode HTTP URLs... The JavaDoc says "Utility class for HTML form encoding"... Is there any other way to do this?</p>