w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Scanner fails to work with files containing Cyrillic characters

To read text, containing another encoding, you should use the constructor of Scanner with additional parameter "encoding". For example, if file, containg russian symbols is in UTF-8 encoding, try something like this:

String path = ... // full path of file
Scanner sc = new Scanner(new FileInputStream(path), "UTF-8");

//read file line by line
while (sc.hasNextLine()){
    //read one line
    String s = sc.nextLine();
    //do something with line

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.