How to import data from a CSV file into Adobe Air app?

I'm going to write an application in a flash builder, and I need the ability to import CSV data into a SQLite database in Adobe Air / flashbuilder.

I have never done anything like this, and I'm not quite sure where to start. I want to do some data manipulation before inserting it again. So really I need to know what steps (classes and functions) I need to use to parse the data from the CSV file into an array that can be manipulated in actionscript?

+3
source share
2 answers

I use casalib for many things, including download. You can use standard as3 material, but that makes it a lot easier. Take a look at CasaLoader .

Then you can use row splitting to extract rows / columns

sqlite stuff is surprisingly simple. Have a look at this link: http://ntt.cc/2008/07/08/sqlite-example-for-adobe-air-working-with-local-sql-databases-with-source-code.html

you can ignore mxml stuff

+1
source

[Update: my answer assumes HTML / Javascript AIR, unlike Flash / Actionscript. There may be better answers on the AS3 side ...]

FileStream CSV. , CSV SQLite, , , ( ).

, FileStream, , . : STDOUT , FileStream .

this.process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, function(event) {
   // call into _stdoutHandler...
});

Foo.prototype._stdoutHandler = function() {
   var nBytes = this.process.standardOutput.bytesAvailable;
   var msg = this.process.standardOutput.readUTFBytes(nBytes);
   // The native process might send us partial lines, due to async IO.
   // Reconstruct the whole lines.
   this._sofar += msg;
   while (true) {
      var idx = this._sofar.indexOf("\n");
      if (idx < 0)
         break;
      if (idx > 0) { // skips blank lines
         var line = this._sofar.substring(0, idx);
         this._foundLine(line);
      }
      if (this._sofar.length > idx + 1) {
         this._sofar = this._sofar.substring(idx+1);
      } else {
         this._sofar = "";
      }
   }
   var lines = this._sofar.split(/\n/);
   if (lines.length > 1) {
      air.trace("programming error: we should have already handled all newlines");
   }
   this._sofar = lines[lines.length - 1];
};

Foo.prototype._foundLine = function() {
   // process a single line of input here...
};
+1

Source: https://habr.com/ru/post/1787370/


All Articles