I just wrote a program for a friend of mine and it contains some greek text, on println
. I wrote the file on Linux, with UTF-8 encoding, but when he opens it on Eclipse(Windows), none of the greek letters appear correctly.
Is there any way to make this work?
I do remember that the greek code page for windows is 737, but how do I tell the compiler to use that code page?
Thank you :)

- 1,551
- 2
- 16
- 21
-
A UTF8 encoded file should work fine. This could be a display issue or a matter of telling the target editor to use UTF8. – pvg Mar 14 '17 at 20:33
2 Answers
It's tricky to get encoded strings through the build chain, because every program that ever touches your source file has to understand and preserve the utf8 encoding. There are simply too many common tools in the english-speaking world that are not reliable in this respect.
My solution is to use ascii encoding, allow the UTF8 markup to persist into the source files, and decode the UTF8 into unicode at runtime.

- 1,792
- 19
- 26
I'm going to guess that your friend is running the program from the command line and Windows is outputting garbage from the UTF-8 bytes there.
This is due to cmd.exe not being set to the UTF-8 code page by default for backwards compatibility with Windows code page 1252.
To set cmd.exe to use UTF-8 use the following command:
chcp 65001
You may need to change fonts as well to something like Lucida Console.
This is actually a duplicate of: Unicode characters in Windows command line - how?
UPDATE
To set the encoding for the current file in Eclipse you must go to Edit -> Set Encoding.
Generally when sharing data you would bundle it in an Eclipse project so that information such as encoding are saved along with the source file. Eclipse inherits encoding from something called a "container" rather than using heuristics to determine the proper encoding of the file.
I can't tell you why exactly it isn't default to UTF-8, perhaps it defaults to the Windows code page as well, but editing files in Eclipse outside of a project is uncommon.
If you're using Eclipse for development then put your source into a project and share that or use a text editor that can handle the encoding detection automatically such as Notepad++ or Sublime Text.
-
Even if it was a cmd problem, which it probably is, why does this happen in Eclipse too? I mean, Eclipse should be able to open a file and display it correctly no matter where it's from. – Kostas Andrianos Mar 14 '17 at 20:55
-
To clarify, Eclipse on your friend's Windows machine is not displaying the source file properly? Did he import your project or did he make a new one? There are a lot of possibilities here. Have your friend look at the project properties and ensure that the encoding is set correctly. – Zhro Mar 14 '17 at 21:33
-
He opened the file with eclipse. The file is straight out of my machine. – Kostas Andrianos Mar 14 '17 at 21:35
-
You say that he opened the 'file'. Do you mean he imported the project... ? – Zhro Mar 14 '17 at 21:43
-
It's not a project. I wrote it on Atom on Linux, and he is opening it as a single Java file on Eclipse. Not importing it, opening as. – Kostas Andrianos Mar 14 '17 at 21:45
-