Save could not be completed. Reason: Some characters cannot be mapped using "Cp1251" character encoding. Either change the encoding or remove the characters which are not supported by the encoding.
原因:Eclipse 默認文件編碼為系統默認 (中文 Windows 為 GBK,俄文/東歐語系為 Cp1251),保存包含中文字符的文件時編碼不匹配。
.settings/org.eclipse.core.resources.prefs,提交版本庫,團隊自動同步。編輯 eclipse.ini,在 -vmargs 前添加:
// 新建測試類
public class EncodingTest {
public static void main(String[] args) {
String s = "中文測試"; // 直接寫中文
System.out.println(s);
System.out.println("file.encoding = " + System.getProperty("file.encoding"));
}
}
運行輸出正常顯示中文且 file.encoding = UTF-8 即成功。
Eclipse 編碼問題本質是 IDE 默認編碼 ≠ 文件實際編碼 ≠ JVM 運行編碼。建議採用 方案三 (項目級 UTF-8) + 方案四 (啟動參數 UTF-8) 雙重保險,並將 .settings 目錄納入版本控制,實現「一鍵導入即正確編碼」的團隊協作體驗。