Encoding problems in the eclipse console

1

When reading the contents of a file to print the same in the eclipse console, I have a pronounced word and it's coming out like this in the console:

é um teste

The correct display is:

é um teste

I checked the eclipse Run options and my encoding is ISO-8859-1

How can I resolve?

For testing, I'm using the following code to do the action:

final Scanner input = new Scanner(new File("/home/douglas/teste.txt"));

        while (input.hasNextLine())
        {
           System.out.println(input.nextLine());
        }
    
asked by anonymous 16.02.2018 / 18:50

1 answer

2

You can specify the correct encoding in constructor of Scanner :

final Scanner input = new Scanner(new File("/home/douglas/teste.txt"), "ISO-8859-1");

while (input.hasNextLine()) {
   System.out.println(input.nextLine());
}

However, I always recommend using encoding UTF-8 that in thesis would work with any characters anywhere in the world as long as everything is encoded in it. ISO-8859-1 and similar encoding have more regional features, thereby creating portability problems.

When the input file is in UTF-8, you would then do this:

final Scanner input = new Scanner(new File("/home/douglas/teste.txt"), "UTF-8");

The constructor without the encoding / charset depends on the platform's default encoding, and because of this, it suffers from portability problems like this.

    
16.02.2018 / 19:00