简体   繁体   中英

Is there way to check charset encoding of .txt file with Java?

有没有办法检查用Unicode编码的文本文件(.txt)或用Java编写的UTF-8?

You cannot know with absolute certainty which charset is used in the general case. I found this to be a good read.

http://illegalargumentexception.blogspot.co.uk/2009/05/java-rough-guide-to-character-encoding.html

Especially the section Automatic detection of encoding .

Uhm, theoretically, how would you know if it is unicode?

This is the real question. Truthfully, you cannot know, but you can make a decent guess.

See: Java : How to determine the correct charset encoding of a stream for more details. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM