天天看點

[字元編碼]Invalid byte 1 of 1-byte UTF-8 sequence終極解決方案

 今天在eclipse中編寫pom.xml檔案時,注釋中的中文被eclipse識别到錯誤:Invalid byte 1 of 1-byte UTF-8 sequence,曾多次遇到該問題,問題的根源是:

The cause of this is a file that is not ​​UTF-8​​​ is being parsed as UTF-8. It is likely that the parser is encountering a byte value in the range ​

​FE​

​​-​

​FF​

​. These values are invalid in the UTF-8 encoding.

但這次很詭異,我使用notepad++将pom.xml的編碼儲存為“UTF-8無BOM”形式,pom.xml檔案内的encoding屬性設定為“UTF-8”,問題依舊啊,郁悶了,難道上述的理論有問題?還是eclipse的bug呢?在網上看了半天,基本都是這麼說的。

第一,可以直接在XML檔案中更改UTF-8為GBK或GB2312

         <?xml   version="1.0"   encoding="GB2312"?>