You have 'exhausted' the bais
when you did IOUtils.copy(bais, new FileOutputStream(myFile));
. You have copied the contents of the bais
to the file, and now the bais
is 'empty'. You will need to either:
- take a copy of the
bais
somehow before writing it to disk - Parse it directly by JDOM and use JDOM to write the XML to disk (
XMLOutputter
) - get JDOM to parse the file (not the
bais
).