Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

How to use Special Chars in Java/Eclipse

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...