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:
- [Solved] DOM parsing XML Error: Content is not allowed in prolog
- The difference between UTF-8 and utf-8-sig
- java.net.SocketException: Broken pipe
- Chrome failed to download word
- java.net.SocketException: socket closed
- signer information does not match signer information of other classes in the same package
- Failed to execute ‘createObjectURL’ on ‘URL’
- How to deal with the prompt “dereferencing type punned pointer will break strict aliasing rules” when compiling C?
- How to Use Array.prototype.slice.call(arguments)
- Python SyntaxError: unexpected character after line continuation character