Search code examples
androidflashfileair

write file in adobe air for android


hello evrey body i have try really hard to write a file to android and so far no secceus. this is the code i am using.

function writeAirFile():void
{
    // Change the folder path to whatever you want plus name your mp3
    // If the folder or folders does not exist it will create it.
    var file:File = new File("/mnt/sdcard/new/new.apk");
     //file.nativePath = "/mnt/sdcard/new/new.apk";
     trace(file.nativePath);
    fileStream.open(file, FileMode.WRITE);
    fileStream.writeBytes(fileData, 0, fileData.length);
    fileStream.close();
    trace("The file is written.");
    trace(file.nativePath);

}

uts need to work but it is not. i already add th permission for local storge writing please i need help thanks a lot for all of you for helping!


Solution

  • Point out custom directory is not best practices better you can use File.applicationStorageDirectory so no need worry about security and permission related issue.

        var file:File = File.applicationStorageDirectory.resolvePath("new/new.apk");
        fileStream.open(file, FileMode.WRITE);
        fileStream.writeBytes(fileData, 0, fileData.length);
        fileStream.close();
        trace("The file is written.");
        trace(file.nativePath); // you can find where it is stored.
    

    Suggestion always use Async mode file operation so that UI freeze won't happen even if file size is too large.