[英]XMLStreamException while trying to parse an xml file downloaded from a ftp
I am downloading a file from and ftp, saving it onto my local filesystem and then reading it with createXMLStreamReader
. 我从和ftp下载文件,将其保存到我的本地文件系统,然后使用createXMLStreamReader
读取它。 When I try and parse it I get this error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[124,316]
. 当我尝试解析它时,我收到此错误: 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. 我确实认识到这是由于<xml
节点之前的二进制字符引起的,但我不确定如何摆脱它们。
I have no control over what is being copied from the ftp and I am using java 1.7
我无法控制从ftp复制的内容,我正在使用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: 我创建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. 不要使用FileReader来读取xml,因为这会破坏xml。 use a FileInputStream. 使用FileInputStream。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.