开发者

how to get the real character encoding of a file java [duplicate]

开发者 https://www.devze.com 2023-02-15 19:12 出处:网络
This question already has answers here: 开发者_开发知识库 Java : How to determine the correct charset encoding of a stream
This question already has answers here: 开发者_开发知识库 Java : How to determine the correct charset encoding of a stream (16 answers) Closed 8 years ago.

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消