How can I determine which encoding the file uses before I read the file?

前端 未结 3 774
余生分开走
余生分开走 2021-01-21 09:07

I\'m facing a problem.

A file can be written in some encoding such as UTF-8, UTF-16, UTF-32, etc.

When I read a UTF-

3条回答
  •  鱼传尺愫
    2021-01-21 09:54

    You can read the first few bytes and try to guess the encoding.

    If all else fails, try reading with different encodings until one works (no exception when decoding and it 'looks' OK).

提交回复
热议问题