How to determine if a String contains invalid encoded characters

前端 未结 10 1337
眼角桃花
眼角桃花 2020-12-02 11:38

Usage scenario

We have implemented a webservice that our web frontend developers use (via a php api) internally to display product data. On the webs

10条回答
  •  醉酒成梦
    2020-12-02 11:53

    You can use a CharsetDecoder configured to throw an exception if invalid chars are found:

     CharsetDecoder UTF8Decoder =
          Charset.forName("UTF8").newDecoder().onMalformedInput(CodingErrorAction.REPORT);
    

    See CodingErrorAction.REPORT

提交回复
热议问题