简体   繁体   中英

In Java can I ask the system to tell me the charset of a file?

There are questions like this , that are about guessing charset/encode of a file. But is there a method in Java to ask the system to tell me before try to guess?

No, there isn't. That's exactly why those questions were asked.

How is "the system" supposed to know? If the encoding isn't declared in some sort of metadata somewhere, then educated guessing is the only thing that can be done.

There is no way for the system to know what encoding was used when the file was written. The system would need to try make an educated guess based on the file contents, same as you would do yourself from your application.

You will need to implement this yourself, or use an external library such as the ones described in the original question you referenced.

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