6
6
6yp9T2014-04-15 10:52:08
Java
6yp9T, 2014-04-15 10:52:08

How to read *.properties files with Russian text in Java?

The files contain the text:

file=Файл
view=Вид
project=Проект
help=Справка

Reading:
properties = new Properties();
        InputStream inputStream = MainMenu.class.getClassLoader().getResourceAsStream("file.properties");
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace(); 
        }

At the output I get:
����
How to read correctly in order to get a normal Cyrillic alphabet?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ruslan Lopatin, 2014-04-15
@6yp9T

The properties files must be in ISO-8859-1 encoding. Characters of other encodings must be escaped (\uXXXX). Use the native2ascii utility to convert. Better yet, use an IDE. They automatically escape characters.

6
6yp9T, 2014-04-15
@6yp9T

I figured it out, IDEA itself converts files into a readable form for both the developer and the compiler

D
Dmitry Tolmachev, 2016-05-08
@todem

And where (in which folder) should I put the file that needs to be read?

F
flud666, 2021-11-16
@flud666

In fact, everything is simple. Use the following read implementation:

try {
            File file = new File("src/main/resources/config.properties");
            properties.load(new FileReader(file));
        } catch (IOException e) {
            e.printStackTrace();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question