Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i read a Russian file in Java?

Tags:

java

file

unicode

I tried adding UTF-8 for this but it didn't work out. What should i do for reading a Russian file in Java?

      FileInputStream fstream1 = new FileInputStream("russian.txt");
      DataInputStream in = new DataInputStream(fstream1);
      BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
like image 246
Figen Güngör Avatar asked Sep 05 '25 13:09

Figen Güngör


2 Answers

If the file is from Windows PC, try either "windows-1251" or "Cp1251" for the charset name.

If the file is somehow in the MS-DOS encoding, try using "Cp866".

Both of these are single-byte encodings and changing the file type to UTF-8 (which is multibyte) does nothing.

If all else fails, use the hex editor and dump a few hex lines of these file to you question. Then we'll detect the encoding.

like image 61
Viktor Latypov Avatar answered Sep 09 '25 15:09

Viktor Latypov


As others mentioned you need to know how the file is encoded. A simple check is to (ab)use Firefox as an encoding detector: answer to similar question

If this is a display problem, it depends what you mean by "reads": in the console, in some window? See also How can I make a String with cyrillic characters display correctly?

like image 41
Arne Avatar answered Sep 09 '25 16:09

Arne