Java : How to determine the correct charset encoding of a stream

前端 未结 15 1691
花落未央
花落未央 2020-11-22 02:06

With reference to the following thread: Java App : Unable to read iso-8859-1 encoded file correctly

What is the best way to programatically determine the correct cha

15条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:17

    An alternative to TikaEncodingDetector is to use Tika AutoDetectReader.

    Charset charset = new AutoDetectReader(new FileInputStream(file)).getCharset();
    

提交回复
热议问题