+3  A: 

Either change your encoding to one which will cope, e.g. UTF-8, or find the relevant Unicode number and use a \uxxxx escape sequence to represent it.

Jon Skeet
How do i find the Unicode number?
Burkhard
Look in the code pages at http://unicode.org
Jon Skeet
+9  A: 

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.

  • Set the global text file encoding preference Workbench > Editors to "UTF-8".
  • If an encoding other than UTF-8 is required, set the encoding on the individual file rather than using the global preference setting. To do this use the File > Properties > Info menu selection to set the encoding on an individual file.

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:

♥ \u2665
♦ \u2666
♣ \u2663
♠ \u2660
Joe Lencioni
I would argue that the second option is preferable because it makes the file more portable between different source encodings. It depends where the characters are of course (String literals? Comments? READMEs?).
McDowell
I would argue that the first option is preferable because anyone who uses any encoding other than UTF-8 (certainly anyone who uses a country-specific encoding) for their source files needs help. :)
Cowan
Java source files are treated as the OS encoding by default (some 8bit CP on Windows; UTF8 on Linux). Not writing ASCII means you need to ensure that devs know about it before they compile and risks introducing bugs if they do not. I18N stuff should be in properties files (UTF8 by definition).
McDowell
+3  A: 

At the menu select File-->Properties and then at the "Text File Encoding" section select "other" and UTF-8

This will allow you to save unicode characters. You might have to remove the characters, save the file and then add them again (that's because to change the properties you need to save the file, but you cannot save it until you have changed the properties).

If you want to make this change for all your project go at Window-->Preferences-->General-->Workspace and do the same (encoding=UTF-8).

idrosid
+2  A: 

Finding the unicode escape sequence: see these Unicode charts. Your characters are in the Misc. Symbols chart, \u2660 and up.

MSalters
+5  A: 

Go to "Windows > Preferences > General > Content Types > Text > {Choose file type} {Selected file type} > Default encoding > UTF-8 and click Update button.

Sepehr Lajevardi