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

Is there a way to check a text file (.txt) encoded using Unicode or UTF-8 with Java?

+7
source share
2 answers

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

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

In particular, the section Automatically detect encoding .

+10
source

Umm, theoretically, how do you know if it is unicode?

This is a real question. Honestly, you may not know, but you can make a decent guess.

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

+2
source