【问题】
Java工程,导入后打开,中文字符串全显示为乱码,怎么办?
java文件导入后显示乱码
【原因】
Java文件与Eclipse开发工具编码格式不一致。
【工具】
Eclipse IDE Oxygen.2 Release (4.7.2)
【解决方法】
修改工作空间默认编码
Window-->Preferences
-->General
-->Workspace窗口
-->Text file encoding
-->选择 Other:UTF-8
-->Apply修改项目工程的编码
只修改某个工程的编码,不影响其它工程。
工程名-->右键-->Properties
-->Resource窗口
-->Text file encoding
-->选择 Other:UTF-8
-->Apply-
修改某类型文件的编码
只修改某种类型文件的编码(如.java文件),不影响其它类型文件。
Window-->Preferences
-->General
-->Content Types
-->Text
-->选择Java Source File
-->下方Default encoding输入:UTF-8
-->Update
-->Apply and Close
修改.java类型文件的编码格式 修改某个文件的编码
只修改某个工程文件的编码。
文件名-->右键-->Properties
-->Resource窗口
-->Text file encoding
-->选择 Other:UTF-8
-->Apply
【总结】
- 修改全局的编码格式,在Window-->Preferences修改
- 修改单个工程、文件的编码格式,在该文件-->右键-->Preferences修改