Search code examples
sqliteactionscript-3apache-flexflash-builderflex4.5

flashbuilder 4.6 - How do I include a sqlite db and copying to storageDirectory


Im completing an app in flashbuilder 4.6 and originally was creating a new sqlite database and table within it, on the fly, when the app was first run... but I now want to include a database file in the /src/views/assets/ folder and when the app is run, copy that file to the application.StorageDirectory -- I cant find any examples of how to pull this off. can anyone shed any light on how the process / actionscript for it would look?


Solution

  • You can use File.copyTo:

    var sourceFile:File = File.applicationDirectory.resolvePath("/views/assets/database.file");
    var destination:File = File.applicationStorageDirectory.resolvePath("database.file");
    sourceFile.copyTo(destination, true);
    

    Where database.file is your sqlite file. You may need to tweak the path for sourceFile to match where your assets are.

    Second parameter of copyTo specifies whether to overwrite any existing file.