2 Replies Latest reply on Nov 4, 2008 2:39 PM by Ardy15jan

    Writing to a text file Security Error

    Ardy15jan Level 1
      I`m having problems with this simple code:

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


      I get SecurityError: fileWriteResource for trying to open the file for writting...
      What is the problem?
      Thank you.
        • 1. Re: Writing to a text file Security Error
          anirudhs Level 2
          Hi,

          As a security restriction, you can't write to the applicationDirectory (of course, you can work around this, but certain OSes will enforce this and your workaround will fail there). Use the applicationStorageDirectory for writing files.
          • 2. Re: Writing to a text file Security Error
            Ardy15jan Level 1
            I have toyed a bit with this applicationStarageDirectory thing...So, just to make it clear for everyone(who will ever read this...): File.applicationStorageDirectory is a path located somewhere on C:\Documents and Settings\<user>\Application Data\.... It`s just a path that you can access via File.applicationStorageDirectory on any computer, that`s why it is "convinient". And it`s always writable, too.

            In other words, you`re not allowed to modify any file in your File.applicationDirectory (the actual application`s directory). Well, that only leaves us with the option to save some information that we need each time we start the program(and that we need to modify while running the program) some place else... You can choose whatever place you want to create and modify the file your application requires, but it`s more "convinient"(and sounds really pro to be storing some stuff in the 'Application Data' directory of the system drive) to store it in the applicationStorageDirectory.

            That`s it :) it`s just a convention, if you will...