I can not understand the reason why Cyrillic transmitted in TextView displayed in diamonds? I read a plain text file by the code below. Return result to TextView . What is the problem, tell me. Encoding in Android studio in the File Encoding section set UTF8.

 fileInputStream = context.openFileInput(MainActivity.DISCOUNTS); bufferedInputStream = new BufferedInputStream(fileInputStream); byte[] input = new byte[fileInputStream.available()]; while ((fileInputStream.read(input)) != -1) { result += new String(input); } 
  • And the file itself is in your encoding?) - xkor
  • Normal txt made in Windows - Yurii
  • The container and OS is nice, but I asked about the encoding, and she’s on Russian Windows in the CP1251 notebook by default. And your reading option counts on UTF-8. Wait, I'll tell you how to fix it ... - xkor
  • Word shows CP1251. - Yurii

1 answer 1

You just need to specify the file encoding when converting it to text:

  fileInputStream = context.openFileInput(MainActivity.DISCOUNTS); bufferedInputStream = new BufferedInputStream(fileInputStream); byte[] input = new byte[fileInputStream.available()]; while ((fileInputStream.read(input)) != -1) { result += new String(input, Charset.forName("cp1251")); // возможно вместо "cp1251" нужно юзать "windows-1251", точно не знаю как эта кодирова оффициально обзывается }