How can I determine which encoding is used by a file before I read the file?

I have a problem.

The file may be written in a character set, such as UTF-8, UTF-16, UTF-32etc.

When I read the file UTF-16, I use the following code:

 BufferedReader in = new BufferedReader(
                           new InputStreamReader(
                           new FileInputStream(file), "UTF16"));

How to determine which encoding is in the file before I read the file?

When I read the UTF-8encoded file with UTF-16, I cannot read the characters correctly.

+3
source share
3 answers

There is no good way to do this. The question you ask is similar to determining the number of numbers by looking at it. For example, what is the radius 101?

. String (byte [] bytes, Charset charset), , , .

+2

. , ( ). .

0

.

, , ( "" ).

0

All Articles