3

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.

2
  • 1
    How are you executing the command on debian - is it via SSH? If so, perhaps your SSH client isn't UTF-8 friendly. Commented Oct 2, 2013 at 15:55
  • ouch! Yeah, it's ssh. Maybe that's the problem but I'm not sure as I'm getting the accents when executing queries agaist the mysql database that's also running on the server. I mean: "mysql> select libelle from echeance where libelle like '% Exécution - Echéance Mois Mo + 1%';" +----------------------------------------------------+ | libelle | +----------------------------------------------------+ | Tranche 2 - Exécution - Echéance mois Mo + 10 | | TC 2 - Exécution - Echéance Mois Mo + 10 65%x2/12 | ..." Commented Oct 2, 2013 at 16:09

2 Answers 2

2

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."

Sign up to request clarification or add additional context in comments.

2 Comments

Had you cared to tell in your question you were using putty, you'd instantly have an answer. Precision is important in those matters.
Yeah, you're right. The thing is I dind't expect Putty to be the problem, as it showed every character I typed. That's why I didn't mention it. But it's also true it's important to give every detail.
1

The console/shell you are using to run your java file also need to be UTF-8 encoding enabled otherwise characters will not be displayed properly. Follow the steps mentioned on the below link to enable UTF-8 on debian shell:

http://jaysonlorenzen.wordpress.com/2009/01/16/set-up-a-debian-linux-machine-to-handle-utf-8-in-a-shell-or-console-app/

4 Comments

Thanks for the answer. In fact, the shell is showing those characters: "root@srv-dev:~# áéíóúuàèìù" <<-- copy-paste from shell
@user1453418 Have u tried to compile and run the file on debian?
No. I haven't. And it's because i'm kinda trying to reduce a bigger problem I have. There's a developper who need to use Eclipse@windows to code an app and after he needs to deploy it over this Debian server. I just have to set up the enviroment and I've just found this java encoding problem.
Thanks again Juned. Apparently it's all set up correctly. root@srv-dev:~# locale charmap UTF-8

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.