Unable to create a file with foreign language char

2019-01-25 03:53发布

问题:

I get the following error, when trying to save a properties file (containing name/value pairs) with foreign language characters. How do I set the encoding?

Save could not be completed. Some characters cannot be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding.

回答1:

That looks like Eclipse.

  1. Cut the whole contents of the file into the clipboard.
  2. Save the (now empty) properties file.
  3. Change the encoding settings of the file (Alt+Enter) to be UTF-8 or whatever you need.
  4. Paste the clipboard into the editor.
  5. Save the editor.


回答2:

I presume its eclipse:

  1. Go to Windows Menu –> Preferences –> General (expand it) –> Workspace (click on it)
  2. Look for a box “Text File Encoding”. Default will be “Cp1252″.
  3. Change radio to select other and select “UTF-8″ from combo box.


回答3:

Assuming it is in Eclipse, easiest way is to choose Save as UTF-8 option present in the error dialog box.

The other answers work well too.



回答4:

Best possible solution for this , which I always do .Is to go the respective file in your workspace open it in notepad++ and make the desired changes. Once done , save the file. Your eclipse will ask you to update the code with the changes . Click yes. And you are all good to go now.