Cyrillic text from file - set utf8 in cmd, unknown characters output anyway

Joined
Nov 11, 2022
Messages
1
Reaction score
0
The first case:
just playing with classes that read file etc.
Java:
import java.io.*;
import java.util.*;
 
 
public class Example {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            String fileName = reader.readLine();
            FileInputStream fStream = new FileInputStream(fileName);
            BufferedInputStream bStream = new BufferedInputStream(fStream);
            while(bStream.available()>0){
                System.out.print((char)bStream.read());
            }
        }catch(IOException ex){ex.printStackTrace();}
    }
}
the .txt file is in utf-8 encoding and it's content is кириллический текст (cyrillic text)
i set chcp 65001 in cmd - but output is unknown symbols

the second case
just cyrillic symbols in char array - want to output them
Java:
public class Example {
    public static void main(String[] args){
        char[] chars = {'а','б','в'};
        for(char ch:chars)
            System.out.println(ch);
    }
}
the .java file with the code is in utf-8 - the compilation gives error unclosed character literal
ok, i'll compile with specifiying the encoding: javac Example.java -encoding utf8
chcp 65001 in cmd of course - the output is unknow symbols

then i save the .java file with encoding windows-1251, cmd to chcp 1251, compile the .java file with -encoding cp1251
and the result is ok... why utf-8 not working?

Please, explain me both cases
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top