java - Reading UTF-8 encoded text from InputStream -


i'm having problems reading japanese/chinese characters input stream.

basically, i'm retrieving json object api.

below code:

    try {         url url = new url(string);         bufferedreader br = new bufferedreader(new inputstreamreader(url.openstream(),standardcharsets.utf_8));         result = br.readline();         br.close();     } catch(exception e) { 

}

for reason, not characters read input stream. problem?

to specific, characters appear when print them out in console, while appear black boxes question marks. also, there no black boxes questions marks when check actual json object through browser.

what see when "printing console" has nothing whether data read or not, has capabilities of console.

if fetching data url, , know sure bytes have fetched represent utf-8 encoded text, , entire data fits on 1 line of text, there no reason why code should not work.

it sounds not sure things work because trying print text console. perhaps console not set render utf-8 encoded text? perhaps console font not have enough glyphs cover font?

here 2 things can try:

  1. instead of writing text console, save file. use command hexdump -c (on *nix system, have no idea how in windows) , @ binary representation make sure expected characters there.

  2. save data text file, open in web browser, since browsers have richer font support console.

if still suspect you've read remote data incorrectly, can run retrieved text through json validator, make sure.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -