In this case, this is not a character encoding problem, it is a content encoding problem; you expect text, but the server uses compression to save bandwidth. If you look at the headers, when you take this URL, you will see that the server you are connecting to returns gzipped content:
GET /0.8/questions/2886661 HTTP/1.1 Host: api.stackoverflow.com HTTP/1.1 200 OK Server: nginx Date: Sat, 22 May 2010 15:51:34 GMT Content-Type: application/json; charset=utf-8 <more headers> Content-Encoding: gzip <more headers>
Thus, you need to either use a smarter client, such as Apache HttpClient, as suggested by stevedbrown (although you need to configure it to make it automatically say Gzip ) or explicitly unzip the stream obtained in your sample code. Try this instead of the line where you declare your input:
BufferedReader in = new BufferedReader(new InputStreamReader(new GZIPInputStream(url.openStream())));
I checked that this works for the url you are trying to capture.
source share