org.xml.sax.SAXParseException: Content is not allowed in trailing section

Website content quality is poor, distribution efficiency is too low how to do?Huawei engineers offer 5 unique skills>>>

Org.xml.sax.saxparseexception: content is not allowed in training section

To sum up, there are two main reasons for this problem

1. Incorrect XML content, such as multiple spaces, line feed, etc. It needs careful investigation

2. Using stream to read stream file is incorrect. The details are as follows: 2

When reading and writing files, it is generally used to read a byte array with a fixed size from the InputStream each time

byte[] array = new byte[1024];

BufferedInputStream buffInput = new BufferedInputStream(inputStream);

FileOutputStream fileOS = new FileOutputStream(targetFile);

BufferedOutputStream buffOS = new BufferedOutputStream(fileOS);

int word = 0;

while ((word = buffInput.read(array)) != – 1){

buffOS.write(array);

}

In the above way, if the last read to the array is less than 1024, the byte of the previous read will also appear in byte [] which leads to the failure of XML parsing. Therefore, the following methods can be adopted:

BufferedInputStream buffInput = new BufferedInputStream(inputStream);

FileOutputStream fileOS = new FileOutputStream(targetFile);

BufferedOutputStream buffOS = new BufferedOutputStream(fileOS);

int word = 0;

while ((word = buffInput.read()) != – 1){

buffOS.write(word);

}

Similar Posts: