4 Replies Latest reply on Nov 1, 2008 5:03 PM by Ardy15jan

    Writing to a text file

    Ardy15jan Level 1
      How do you write to an external text file with AIR without getting a security error?...
      I`m using a FileStream and I open the file in FileMode.WRITE, and that`s all I have to do to get a Security Error.
      This is my code:

      import flash.filesystem.*;
      var file:File = File.applicationDirectory.resolvePath("test.txt");
      var fStream:FileStream = new FileStream();
      fStream.open(file, FileMode.WRITE);


      That`s it... I don`t even get to actually try to write something in the file...
        • 1. Re: Writing to a text file
          abeall Level 3
          Use File.applicationStorageDirectory, not File.applicationDirectory.

          quote:

          Note: You cannot write to files or directories that have paths that use the app URL scheme. Also, you cannot delete or create files or folders that have paths that use the app URL scheme. Modifying content in the application directory is a bad practice, for security reasons. If you want to store application-specific data, consider using the application storage directory (File.applicationStorageDirectory). If you want any of the content in the application storage directory to have access to the application-priveleged functionality (AIR APIs), you can expose that functionality by using a sandbox bridge.
          • 2. Re: Writing to a text file
            Ardy15jan Level 1
            Oh... I think I understand what you mean. I have heard of using the application storage, but I didn`t really know what that meant. I`ll try it as soon as I can.
            Thanks for your help.

            P.S.: So does the application storage thing mean that I`m modifying a copy of the files in the application directory? Is the application directory updated for the next session?
            And: Can I open a file outside of the application directory for writting without the storage thing?(which I still don`t understand what is exactly)
            • 3. Re: Writing to a text file
              abeall Level 3
              "So does the application storage thing mean that I`m modifying a copy of the files in the application directory? Is the application directory updated for the next session?"

              No, applicationStorage is just a convenient place to store data which is unique to your application. Anything you store there will remain persistent.

              "Can I open a file outside of the application directory for writting without the storage thing?"

              Yes, but there might be some limitations. That's one of the conveniences of applicationStorageDirectory, you always know it will be writable.
              • 4. Re: Writing to a text file
                Ardy15jan Level 1
                Thank you for your help and time :)