Skip to main content
Damon Edwards
Inspiring
February 26, 2009
質問

SecurityError: fileWriteResource

  • February 26, 2009
  • 返信数 5.
  • 22779 ビュー
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)
このトピックへの返信は締め切られました。

返信数 5

Participant
September 6, 2011

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();
March 3, 2009
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!
Damon Edwards
Damon Edwards作成者
Inspiring
February 26, 2009
As I expected. Thanks Ted.
Participant
July 3, 2009

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/.

Participant
August 17, 2010

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

Adobe Employee
February 26, 2009
You should not write the application directory.

-ted
Participant
May 30, 2011

...

Damon Edwards
Damon Edwards作成者
Inspiring
February 26, 2009
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.