I am downloading a file from and ftp, saving it onto my local filesystem and then reading it with createXMLStreamReader. When I try and parse it I get this error:javax.xml.stream.XMLStreamException: ParseError at [row,col]:[124,316]. When I copy and paste it to another file manually everything works fine. I have tried copying the file using this, the file gets copied but I am still getting the same error. I do realize that this is caused because of binary characters before the <xml node but I am not sure on how to get rid of them.
I have no control over what is being copied from the ftp and I am using java 1.7
My code for retrieving the file:
client.connect("ftp.domain.com");
client.login("user", "password");
String filename = assetsPath + "/ftpExport.xml";
fos = new FileOutputStream(filename);
client.retrieveFile("/Export.xml", fos);
My code to create the StreamReader:
inputFactory = XMLInputFactory.newInstance();
File f = new File(Parser.class.getProtectionDomain().getCodeSource().getLocation().getPath());
assetsPath = f.toString()+"/../assets";
xmlReader = inputFactory.createXMLStreamReader(
new FileReader(assetsPath + "/Export.xml"));
don’t use a FileReader for reading xml as this can corrupt the xml. use a FileInputStream.