M
M
marchSolution2015-03-20 00:40:43
Java
marchSolution, 2015-03-20 00:40:43

Does not accept Russian text when launching a jar file from the console, how can I fix it?

The crux of the matter is as follows. As an educational project, I decided to write a console application to test knowledge of English words, the program is primitive and does not pretend to be anything.
The code sucks while I'm learning. The bottom line is, everything works, checks the words, displays the result, you load any prepared txt and it works. Through IDEA.
BUT when compiling and running from the command line, it does not perceive the Russian language.
If the test word is in English, then the answer counts.
How can I fix this, maybe the problem is in the encoding?
An example of a txt code:
cat
cat
dog
dog
mouse
mouse
book
book
If so, then the check works correctly:
cat
koshka
dog dog dog
mouse
Assigning an
encoding to InputStream did not help.
Thanks in advance.
Method source code:

public class Printed {

    // построчное чтение из файла
    public static void FileReader() throws Exception {
        String s;
        int j = StringMeter.StringCounter();

        String words[] = new String[j];
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        int answerCount = 0;
        Scanner scanner = new Scanner(System.in);
        String answer;
        // Вводим в консоль путь к файлу с расширением
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            // пробуем прочитать файл, если файл не найдем перехватываем исключение и пробуем снова
            // при успешном чтении цикл прерывается и распечатывает содержимое в консоль
            try {
                System.out.print("Enter filename : ");
                s = buf.readLine();
                buf = new BufferedReader(new FileReader(s));
                break;
            } catch (Exception e) {
                System.out.println("Файл не найден!");
                continue;
            }
        }



        for(int i = 0; i < j;i++){
            words[i]= buf.readLine();
        }

        for(int i = 0; i < j;i = i +2){
            System.out.println(words[i]);
            String string = buffer.readLine();
            if(string.equals(words[i+1])){
                answerCount++;
            } else System.out.println("     НЕ ВЕРНО!");

        }



        //System.out.println(answerCount);

        System.out.println("Ваш результат: " + answerCount + " из " + j/2);


        buf.close();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asd111, 2015-03-20
@asd111

txt in what encoding? Try to save txt in utf-8, also try to run java with flags -Dfile.encoding=UTF-8i.e.java -jar -Dfile.encoding=UTF-8 myJar.jar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question