title: Java - Convert String to valid URI object
body: <p>I am trying to get a <code>java.net.URI</code> object from a <code>String</code>. The string has some characters which will need to be replaced by their percentage escape sequences. But when I use URLEncoder to encode the String with UTF-8 encoding, even the / are replaced with their escape sequences.</p>
  
  <p>How can I get a valid encoded URL from a String object?</p>
  
  <p><strong><a href="http://www.google.com?q=a" rel="noreferrer">http://www.google.com?q=a</a> b</strong> gives <strong>http%3A%2F%2www.google.com...</strong> whereas I want the output to be <strong><a href="http://www.google.com?q=a%20b" rel="noreferrer">http://www.google.com?q=a%20b</a></strong></p>
  
  <p>Can someone please tell me how to achieve this.</p>
  
  <p>I am trying to do this in an Android app. So I have access to a limited number of libraries.</p>