The first case:
just playing with classes that read file etc.
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
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
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();}
}
}
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);
}
}
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