I use the iter-style API to parse XML stream with stacks.
I have a small code that cuts a large XML file into several files.
Then I read the flow properly, but while writing, I get the file with the strange character (encoding problem)
public static zero main (string [] Args) throws an exception {int offre = 0; Int i = 0, j = 0; String data = ""; String name = "flux0.xml"; XMLEventReader Reader = XMLInputFactory.newInstance (). Create XMLEventReader (new java.io.FileInputStream ("CJ.xml")); FileOutputStream Output = New FileOutputStream (nom); XMLOutputFactory xmlof = XMLOutputFactory.newInstance (); XMLEventWriter author = xmlof.createXMLEventWriter (output); XMLEventFactory eventFactory = XMLEventFactory.newInstance (); While (reader.hasNext () / * & J & lt; 3000 * /) {XMLEvent event = (XMLEvent) Reader. If (event.isStartElement ()) {if (event.asStartElement (). GetName (). GetLocalPart () == "Offer") {offre ++; }} If (offray == 5000) {i ++; Nom = "flow" + i + "xml."; Output = new FileOutputStream (nom); Author = xmlof.createXMLEventWriter (Output); If (event.getEventType () == event.CHARACTERS) {character character = event.asCharacters (); String text = character GateData (); Charset encoder encoder = Charset.fairname ("UTF-8"). New incandescent (); Data = new string (encoder.xcode (charbuffer.pop (texeter.cochrorare)). Array ()); Author.add (eventFactory.createCharacters (data)); } And {author.ed (incident); } Nom = "flux" + i + ".xml"; Offre = 0; } Else {if (event.getEventType () == event.CHARACTERS) {letter characters = event.asCharacters (); String text = character GateData (); Charset encoder encoder = Charset.fairname ("UTF-8"). New incandescent (); Data = new string (encoder.xcode (charbuffer.pop (texeter.cochrorare)). Array ()); Author.add (eventFactory.createCharacters (data)); } And {author.ed (incident); }} Writer.flush (); }
Four encodings with this code are forced by your author
string output encoding = "UTF-8"; FileOutputStream fos = New FileOutputStream (aFile); OutputStreamWriter osw = new output speed water (fos, outputEncoding);
Comments
Post a Comment