Skip to main content
Damon Edwards
Inspiring
Feb 26, 2009 9:24 PM UTC
Question

SecurityError: fileWriteResource

Hello all, I'm having a little difficulty reading, then writing to a XML file in the applicationDirectory. I can read from it fine, parse the results, close the stream. However, when it comes time to write to the file, I get this error thrown:

SecurityError: fileWriteResource
at runtime::SecurityManager$/checkPrivilegeForCaller()
at flash.filestream::FileStream/open()
... (the rest is my stuff)
This topic is closed to new replies. Start a new post to keep the conversation going.

10 replies

Participant
Sep 6, 2011 10:47 AM UTC

Hi, this is how I solved/hacked the problem.

var filePath:String = "app:/" + FileNames.DATA_COMMENTS_DIR + "/" + fileName;

var appDirFile:File = new File(filePath);
var xmlFile:File = new File(appDirFile.nativePath);
var fileStream:FileStream = new FileStream();
fileStream.open(xmlFile, FileMode.WRITE);
fileStream.writeUTFBytes(newXMLStr);
fileStream.close();
Translate
Mar 3, 2009 7:32 PM UTC
I am trying to do the same thing. I see now that is it read-only. However, when an AIR application is uninstalled the applicationStorageDirectory is not cleared or removed. I am trying to create a screen that thanks the user upon install, meaning when the app is uninstalled I would need to clear out the memory of it ever being installed. The applicationDirectory is removed, but it isn't writable. HMM, any suggestions guys?

Thanks!
Translate
Damon Edwards
Inspiring
Feb 26, 2009 10:41 PM UTC
As I expected. Thanks Ted.
Translate
Participant
Jul 3, 2009 7:17 AM UTC

The solution is to use a line like

myFile = new File(pathAsString);

so use the File(path) constructor. Then you will be able to write files in the application directory. Solution found at http://exaflood.de/syrotech/air-securityerror-filewriteresource/.

Translate
Participant
Aug 17, 2010 3:03 AM UTC

This does not seem to be working in AIR 2.  Can anyone else confirm this?

Translate
Adobe Employee
Feb 26, 2009 10:30 PM UTC
You should not write the application directory.

-ted
Translate
Participant
May 30, 2011 11:17 PM UTC

...

Translate
Damon Edwards
Inspiring
Feb 26, 2009 10:02 PM UTC
ahh, the application directory is read only. so, i'm assuming that goes for any child directories as well? The file I'm trying to read-write to is a file I've included in the packaging of the application. It's not in the same directory as the application, but one folder down, in a folder call "security". I must be assuming correctly that these are read only as well, and that I should be using applicationStorageDirectory instead?

That'll work, but sucks because being able to include a default file saves time coding since I don't have to write the logic to check if it exists first, then create if doesn't, and so on.
Translate