Search code examples
javaeclipseencodingutf-8locale

UTF-8 encoding not working with Eclipse java application


I've got a little encoding problem somewhere that I can't fix.

I've got the next java file:

public class Main {

    public static void main(String[] args) {
        System.out.println("áéíàèì€aei");
    }
}

The file charset encoding is UTF-8 and I'm using Eclipse over Windows to edit and compile it. After having the file compiled I move the .class file to a Debian server, whose charset encoding is also UTF-8, as it's shown here:

root@srv-dev:~# locale
LANG=fr_FR.UTF-8
LANGUAGE=
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=fr_FR.UTF-8

and when i run the app i'm getting:

root@srv-dev:~# java Main
áéíàèìâ¬aei

I'm Eclipse, I've set UTF-8 as project encoding by left-clicking in properties and going to resources/text file encoding / Other : UTF-8.

I can't see what else I would change. There's something I might be missing but I can't find it.


Solution

  • The problem was related to the putty configuration. It set the remote charset as ISO-8859-1.

    And I'm guessing the reason why mysql query result showed the accents was because it's also using ISO-8859-1 charset. To configure putty, just follow the next link:

    Configuring PuTTY to use UTF-8

    To change encoding permanently, just follow this answer -that you'll actually find in the link's comments, but I don't want you to miss it so here it is:

    "In order to make these changes permanent in Putty, you open up Putty, make the changes you want to save, then click back on the Session window, click on the "Default Settings" under Saved Sessions, and then click on Save. Next time you open Putty whatever you changed prior to clicking save will still be in effect."