M
M
mao_z2015-12-24 15:13:57
Java
mao_z, 2015-12-24 15:13:57

What happens to the encoding when Java strings are concatenated?

I output it to the console like this: The utterance variable contains the text from the file in UTF8 encoding. In the console I get the following: In the debugger, the variable contains normal text. Tried different ways. Well, for example: System.setOut(new PrintStream(System.out, true, "cp866")); Tried: With all methods, either the first half is displayed incorrectly or the second. How is it that one half of the string is in one encoding, and the other half is in another. Can anyone explain the essence of the problem? System.out.println("Распознано: " + utterance);
Распознано: С?РёС?С?С?
-Dfile.encoding=utf-8

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Titov, 2015-12-24
@titov_andrei

In the console (cmd.exe), before calling the compiler, switch the code page with the command
. It is enough to do this once every time you start the console. javac in Russian-language Windows displays messages in cp1251 encoding, and the console uses cp866.

⚡ Kotobotov ⚡, 2015-12-24
@angrySCV

it is better to immediately stop using windows and their console in particular, once and for all, unless of course you want to know this wonderful world of Windows kostylirovanie.

O
Odissey Nemo, 2016-02-07
@odissey_nemo

Perhaps your source is on disk in Windows-1251 encoding. Save it as UTF-8 (no BOM, most likely)). If that was the case, then, according to kr. least, now the entire output string will be in a single encoding. And it should be displayed or distorted evenly)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question