Reading file Problem

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Yenaphe
Posts: 84
Joined: February 3rd, 2009, 6:30 pm
Location: Paris - France
Contact:

Hi everyone,

up to now, i've had no problem in using this bit of code to read the content of a file and store it line by line in an array.

Code: Select all

			var j = 0;
			var fileOK = XmlFile.open("r","XML","???");
			if (fileOK){		
					var F_TXT = "";
					
					while (!XmlFile.eof){
							L_TXT = XmlFile.readln(); // Parsing
							if (L_TXT == "") L_TXT = "\r" ;
							F_TXT = F_TXT+"\n"+ L_TXT;
							j++;
							writeLn("Reading line: "+j);
							} // fin while eof
					XmlFile.close();

					var txtArray;
					var lineArray;
					
					txtArray = F_TXT.split( '\n' );
				}
			}
I want to create some kind of Xml importer, but this code crashes on very long files, and it crashes randomly.

I have a 90000 line Xml, and the script never reads beyond 64000, and crashes between 10400 and 64000. In fact it crashes on files longer than 10000 lines (which for xml is quite small).

Any idea ?
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Perhaps you've reached the maximum allowed string length in your F_TXT variable...
That could cause a memory corruption, and can explain the non consistent behaviour.
In order to check that, see if an XML file with shorter lines, reaches more lines before it crashes.
If so, consider splitting the string every once in while, before reaching EOF, or even after every line read from file.

Another possibility is that your txtArray array reached its limit.
To make sure it is the F_TXT string variable and not the array, i would remove the line:
txtArray = F_TXT.split( '\n' );
and see if it still crashes. If it does, it is probably the string variable reaching its max length.
Post Reply