开发者

How to get bytes as UTF-8Y in Java

开发者 https://www.devze.com 2023-03-16 02:39 出处:网络
I am using a sax parser to parse the xml file which has an encoding of utf-8y. How can I specify that 开发者_运维技巧in the sax parser or the input source ? I always get a parse exception I presume yo

I am using a sax parser to parse the xml file which has an encoding of utf-8y. How can I specify that 开发者_运维技巧in the sax parser or the input source ? I always get a parse exception


I presume you're reading the file via an InputStream? The parser should be able to determine the file type from the XML header. If you read the file into a string, and then parse that the it tends to go pear-shaped


Just to make sure: is that 'Y' something that is included in 'encoding' value of XML document? Then I am not surprised you get an error -- there is no such encoding. I assume this is an error in whatever produced the document and should be fixed.

But on your side, you have two main options:

  1. Construct an InputStreamReader yourself from InputStream, passing "UTF-8" as encoding
  2. Modify input document before parsing to remove that 'y' from there

First approach is simple, and most parsers should be ok with it. Second option can be used if first doesn't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消