0

My string contains special characters (eg: �tøkiligar) and when decoding it using XMLDecoder it throws ArrayIndexOutOfBoundsException. Is there anyway to change the decoding format to another format(ISO-8859-1) than UTF-8?

java.lang.ArrayIndexOutOfBoundsException: 0 at java.beans.XMLDecoder.readObject(Unknown Source)

Amy
  • 23
  • 10
  • XMLDecoder works on some kind of InputStream. Change that to an input where you can set the encoding to ISO-8859-1. – Ralf Renz Feb 27 '19 at 08:15
  • Possibly related (check comments): https://stackoverflow.com/questions/27492710/java-xmlencoder-xmldecoder-and-utf-8 – Amongalen Feb 27 '19 at 08:16
  • The exception is thrown, if the input stream contains no objects. Are you sure you are reading from a document which was created using `XMLEncoder`? Please add the code which reads the input. – Würgspaß Feb 27 '19 at 10:28
  • Previously I used XMLDecoder(new ByteArrayInputStream(xml.getBytes()))). Then when I used XMLDecoder(new ByteArrayInputStream(xml.getBytes("UTF-8")))) it worked. @RalfRenz thanks your answer helped. – Amy Feb 28 '19 at 04:04

0 Answers0