11

错误:非法字符:“\ufeff”  Java python

 3 years ago
source link: https://blog.csdn.net/weixin_40959890/article/details/111942606
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

IDEA导入开源的项目的时候,非法字符:“\ufeff”,编码问题,这一般这个项目是用eclipse开发的。主要原因是: Eclipse可以自动把UTF-8+BOM文件转为普通的UTF-8文件

解决办法:UTF-8 换成 GBK 然后再换成UTF-8 就好了

方法二:

将这些报错的文件拷贝到一个目录中,然后用notpad++打开,点击工具类上的 编码,将 以uft8格式编码 转为 以utf8无BOM格式编码,然后保存,再覆盖idea中对应的文件。

方法三:

将文件用EditPlus打开,然后选择Document(文件),再选择Convert Encoding(编码转换)如下图操作

再弹出框中选择 UTF-8即可

上面是转换一个文件的编码,如何转换整个项目的编码:

Python

使用python打开txt文件,总是开始出现\ufeff,例如使用下面python代码打开a.txt文件,就会报这个错误

lines = open(osp.join(rootpath,'test.txt'),'r',encoding='utf-8').read().rstrip().split('\n')

解决办法:修改解码规则


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK