java 如何获取文件的真实字符编码
关于在 java 中获取 .html .txt .java 等文件的真实编码有什么想法吗?
由于有些源代码不是utf-8,我想将它们更改为utf-8。
Any idea about gettin the real encoding of a file like .html .txt .java and etc in java?
Since some source codes are not utf-8,I wantto change them to utf-8.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,不可能总是准确检测文本文件的字符编码是什么 - 文本文件中没有存储任何内容来明确告诉您字符编码是什么。您可以做出一些明智的猜测,但不要指望您总是能够准确地找出文本文件的字符编码是什么。
cebewee 在评论中发布的链接提供了有关如何检测字符编码的更多信息一个文本文件是。
In general, it is not possible to always detect exactly what the character encoding of a text file is - there's nothing stored in a text file that tells you explicitly what the character encoding is. You can make some intelligent guesses, but don't expect that you'll always be able to find out exactly what the character encoding of a text file is.
The link that cebewee posted in the comments has more information on how to detect what the character encoding of a text file is.
您可以使用 UTFCast 等工具批量转换文件编码。只需在所有源文件上运行它们即可完成。在Linux上,您可以使用'iconv'来转换文件编码。
You can use tools like UTFCast to batch convert file encoding. Just run them on all of your source files and you should be done. On linux, you can use 'iconv' to convert file encoding.