Reading utf-8 with a scanner

I am having problems with UTF-8 encoding while using Scanner . An example of two lines of my data file:

000001 MΔ—lynas Tadas 63210309683 V 2003/03/17 2016/03/17 
000002 Raudonas Tomas 65505023282 V 2006/01/26 2018/01/26

      

I am currently using the Scanner to read the text separately and not for the whole line as it is more convenient, but due to the encoding it does not read correctly. I've read about using InputStream , etc., but I don't want to deal with messy chopping. Is there a way to use Scanner with UTF-8?

+3


source to share


2 answers


This piece of code might help:



Locale loc = new Locale("es", "ES");
Scanner sc = new Scanner(new FileInputStream(file), "UTF-8");
sc.useLocale(loc);

      

+5


source


You tried, Scanner myScanner = new Scanner("myFile", "UTF-8");



+3


source







All Articles