Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing large text files with Adobe AIR
    primarykey
    data
    text
    <p>I am trying to do the following in AIR:</p> <ol> <li>browse to a text file</li> <li>read the text file and store it in a string (ultimately in an array)</li> <li>split the string by the delimiter \n and put the resulting strings in an array</li> <li>manipulate that data before sending it to a website (mysql database)</li> </ol> <p>The text files I am dealing with will be anywhere from 100-500mb in size. So far, I've been able to to complete steps 1 and 2, here is my code:</p> <pre><code>&lt;mx:Script&gt; &lt;![CDATA[ import mx.collections.ArrayCollection; import flash.filesystem.*; import flash.events.*; import mx.controls.*; private var fileOpened:File = File.desktopDirectory; private var fileContents:String; private var stream:FileStream; private function selectFile(root:File):void { var filter:FileFilter = new FileFilter("Text", "*.txt"); root.browseForOpen("Open", [filter]); root.addEventListener(Event.SELECT, fileSelected); } private function fileSelected(e:Event):void { var path:String = fileOpened.nativePath; filePath.text = path; stream = new FileStream(); stream.addEventListener(ProgressEvent.PROGRESS, fileProgress); stream.addEventListener(Event.COMPLETE, fileComplete); stream.openAsync(fileOpened, FileMode.READ); } private function fileProgress(p_evt:ProgressEvent):void { fileContents += stream.readMultiByte(stream.bytesAvailable, File.systemCharset); readProgress.text = ((p_evt.bytesLoaded/1048576).toFixed(2)) + "MB out of " + ((p_evt.bytesTotal/1048576).toFixed(2)) + "MB read"; } private function fileComplete(p_evt:Event):void { stream.close(); //fileText.text = fileContents; } private function process(c:String):void { if(!c.length &gt; 0) { Alert.show("File contents empty!", "Error"); } //var array:Array = c.split(/\n/); } ]]&gt; &lt;/mx:Script&gt; </code></pre> <p>Here is the MXML</p> <pre><code>&lt;mx:Text x="10" y="10" id="filePath" text="Select a file..." width="678" height="22" color="#FFFFFF" fontWeight="bold"/&gt; &lt;mx:Button x="10" y="40" label="Browse" click="selectFile(fileOpened)" color="#FFFFFF" fontWeight="bold" fillAlphas="[1.0, 1.0]" fillColors="[#E2E2E2, #484848]"/&gt; &lt;mx:Button x="86" y="40" label="Process" click="process(fileContents)" color="#FFFFFF" fontWeight="bold" fillAlphas="[1.0, 1.0]" fillColors="[#E2E2E2, #484848]"/&gt; &lt;mx:TextArea x="10" y="70" id="fileText" width="678" height="333" editable="false"/&gt; &lt;mx:Label x="10" y="411" id="readProgress" text="" width="678" height="19" color="#FFFFFF"/&gt; </code></pre> <p>step 3 is where I am having some troubles. There are 2 lines in my code commented out, both lines cause the program to freeze.</p> <p>fileText.text = fileContents; attempts to put the contents of the string in a textarea <br/> var array:Array = c.split(/\n/); attempts to split the string by delimiter newline</p> <p>Could use some input at this point... Am i even going about this the right way? Can flex/air handle files this large? (i'd assume so) This is my first attempt at doing any sort of flex work, if you see other things ive done wrong or could be done better, i'd appreciate the heads up!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload