eclipse编码格式(优先级)

来源:互联网 发布:ssh服务默认端口为什么 编辑:程序博客网 时间:2024/06/06 21:06


eclipse中文显示乱码问题总结

将外部源文件导入到Eclipse工程后,经常遇到各种乱码问题,究其原因主要是因为文件本身的encoding type与eclipse用于打开改文件的编辑器所使用的encoding type不一致导致。那么eclipse的编辑器到底是如何决定采用哪种encoding type编辑某一个文件呢?

我们需要知道编辑器当前是采用什么encoding type在编辑文件,可以选中文件右键property->resource看到:

这里根据个人的使用经验,可能会出现三种情况:

1、 inherit from container

2、 determined from content type: xxx

3、 determined from content: xxx

那么以上三种决定文件encoding type判定分别表示什么意思呢?

熟悉eclipse使用的兄弟都清楚,encoding type相关有四个地方可设置:

1、全局(windows->reference->General->workspace)

2、工程(project->property->resource)

3、文件(选中文件右键property->resource),可看到当前编辑器所使用的encoding type,这里可以直接更改编辑器编辑该文件时采用的encoding type并直接生效。

4、全局文件的content type(windows->reference->General->contest type->Default encoding)

1、2、3逐级继承,这个比较容易理解,这里不详细介绍。

值得一提的是,在工具可设置的范围内4优先级是最高的,即如果设置了某类型文件的content type的default encoding,那编辑器会优先根据该类型文件设置的默认编码格式来编辑文件,而不管前面的1、2的设置。

0 0
原创粉丝点击