After all, no Russian letters are displayed correctly, but the Latin ones and numbers are correct.
How can I fix this problem? Any ideas?
UPDATE 1
BufferedReader br = new BufferedReader(new FileReader("file.txt",StandardCharsets.UTF_8));try {StringBuilder sb = new StringBuilder();String line = br.readLine();while (line != null) {sb.append(line);sb.append(System.lineSeparator());line = br.readLine();}String everything = sb.toString();System.out.println(everything);} catch (IOException e) {throw new RuntimeException(e);} finally {br.close();}
This one doesn't work too.
UPDATE 2
Here's the console settings.
There is no benefit from this.
UPDATE 3
Expected result (the original text): "Кстати, в Индонезии есть часть страны называемой Java...Карл, Java!!! Еще и страннее то, что как бы Индонезия кажется такимродным.... с чего это вдруг?"
Actual result (what is displayed in console): "Кстати, в �?ндонезии есть часть страны называемой Java...Карл, Java!!! Еще и страннее то, что как бы �?ндонезия кажется такимродным.... с чего это вдруг?"
First try to use method getBytes(Charset charset)
instead of just getBytes()
in your line:
System.out.println(new String(everything.getBytes(),StandardCharsets.UTF_8));
This may solve your problem. Also, for diagnostics I would suggest to try convert your string that you think contains russian characters into unicode sequence and see if your string really contains russian characters and your problem is only display problem or that your String doesn't have the right chars to begin with. I wrote my own feature that can easily convert string into unicode sequence and vice-versa. Here how it works:There is an Open Source java library MgntUtils written and maintained by me that has a Utility that converts Strings to unicode sequence and vise versa:
result = "Hello World";result = StringUnicodeEncoderDecoder.encodeStringToUnicodeSequence(result);System.out.println(result);result = StringUnicodeEncoderDecoder.decodeUnicodeSequenceToString(result);System.out.println(result);
The output of this code is:
\u0048\u0065\u006c\u006c\u006f\u0020\u0057\u006f\u0072\u006c\u0064Hello World
The library can be found at Maven Central or at Github It comes as maven artifact and with sources and javadoc
Here is javadoc for the class StringUnicodeEncoderDecoder