Encoding an URL should be a very simple task. First time I encountered this I did not expect having to do an online research to find an article showing how to do it without using deprecated classes like URLEncoder.

Anyhow. Below a solution that works for me.

Source Code

1
2
3
4
5
6
7
8
9
10
11
	@Test
	public void testUriEncoding() throws URISyntaxException,
			MalformedURLException {
		final String add = "http://www.huhu.com/{ähm}";
		URL url = new URL(add);
 
		URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(),
				url.getQuery(), null);
 
		System.out.println(uri.toASCIIString());
	}