java - When writing to text file, around 4,000 values are not written -
java - When writing to text file, around 4,000 values are not written -
i've been trying parse xml file store every node need array/arraylist; i've tried both. parser able grab every value want , store array(list). printed length after , 262,144 values long(512*512). however, 1 time seek print array text file, leaves around 3800 values missing. have tried quite few things work, no matter how many values seek store (even when trying xml around 147,000 values) still leaves out around 4000 values. here's parser/writer.
public class reader { private string path; public static void main(string[] args) { document xmldoc = getdocument("./src/porc.tmx"); string filename = "out.txt"; string[] array = new string[262144]; seek { nodelist gidlist = xmldoc.getelementsbytagname("tile"); for(int = 0; < gidlist.getlength(); i++) { node g = gidlist.item(i); if(g.getnodetype() == node.element_node) { element gid = (element) g; string id = gid.getattribute("gid"); array[i]=id; } } printwriter outputstream = new printwriter(filename); for(int j = 0; j < 262144; j++) { outputstream.println(array[j]); } } catch(exception e) { e.printstacktrace(); } } private static document getdocument(string docstring) { seek { documentbuilderfactory mill = documentbuilderfactory.newinstance(); factory.setignoringcomments(true); factory.setignoringelementcontentwhitespace(true); factory.setvalidating(false); documentbuilder builder = factory.newdocumentbuilder(); homecoming builder.parse(new inputsource(docstring)); } catch(exception ex) { system.out.println(ex.getmessage()); } homecoming null; }
i suggest close outputstream
@ end of processing.
printwriter outputstream = null; seek { nodelist gidlist = xmldoc.getelementsbytagname("tile"); for(int = 0; < gidlist.getlength(); i++) { node g = gidlist.item(i); if(g.getnodetype() == node.element_node) { element gid = (element) g; string id = gid.getattribute("gid"); array[i]=id; } } outputstream = new printwriter(filename); for(int j = 0; j < 262144; j++) { outputstream.println(array[j]); } } catch(exception e) { e.printstacktrace(); } { if (outputstream != null) outputstream.close(); }
java xml arraylist
Comments
Post a Comment