thomas8wp
thomas8wp

Reputation: 2411

URLDecoder giving unexpected value on UTF-8 url parameter

I'm using java.net.URLDecoder to decode a URL parameter that is supposed to be encoded in UTF-8. A quick test reveals I'm getting ? instead of in the output. Here's the code:

System.out.println(java.net.URLDecoder.decode("A%E2%88%A9B%0AYour+answer+is%3A+3", "UTF-8"));

And as output I'm getting:

A?B
Your answer is: 3

When I plug the string A%E2%88%A9B%0AYour+answer+is%3A+3 into web decoders (e.g. here or here), they get it right:

A∩B
Your answer is: 3

Does anyone know what I'm doing wrong. Is this not actually UTF-8? The string is coming from com.google.gwt.http.client.URL.encodeQueryString(), which claims UTF-8 encoding.

Upvotes: 1

Views: 108

Answers (1)

thomas8wp
thomas8wp

Reputation: 2411

As Siguza and VGe0rge pointed out, the Java code was running correctly, but Eclipse's console will not display in UTF-8 by default. A solution to that issue can be found here.

Upvotes: 2

Related Questions