How can I use/display characters like ♥, ♦, ♣, or ♠ in Java/Eclipse?
When I try to use them directly, e.g. in the source code, Eclipse cannot save the file.
What can I do?
Edit: How can I find the unicode escape sequence?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that the characters you are using cannot be represented in the encoding you have the file set to (Cp1252). The way I see it, you essentially have two options:
Option 1. Change the encoding. According to IBM, you should set the encoding to UTF-8. I believe this would solve your problem.
Option 2. Remove the characters which are not supported by the ‘Cp1252’ character encoding. You can replace the unsupported characters with Unicode escape sequences (\uxxxx). While this would allow you to save your file, it is not necessarily the best solution.
For the characters you specified in your question here are the Unicode escape sequences: