Skip to main content
Participating Frequently
October 27, 2011
Question

Error #3003: File or directory does not exist with FileMode.WRITE

  • October 27, 2011
  • 1 reply
  • 3685 views

In short, here's the code:

var profileName:String ="Player1";

var fileName:String = "\\Data\\Profiles\\"+profileName+".dat";

var saveFile:File = File.documentsDirectory;

saveFile = saveFile.resolvePath(fileName);

var str:String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

str+="\r\n <Plants>";

str+="\r\n </Plants>";

var localFileStream:FileStream = new FileStream();

localFileStream.open(saveFile, FileMode.WRITE);

localFileStream.writeMultiByte(str, "utf-8");

FileMode.WRITE should have created the file by itself, how come it still throws Error 3003?

Also, I traced the fileName string and it shows \Data\Profiles\Player1.dat is that the correct way to assign path?

This topic has been closed for replies.

1 reply

Inspiring
September 22, 2015

I had this problem with File.applicationDirectory on Windows and it turned out to be a permissions issue because applicationDirectory is read-only. So 3003 can be a "SecurityError: fileWriteResource" in disguise. Oddly, if I referenced a subfolder eg "/some/thing.txt" (this slash syntax also works), it would create the directory but couldn't create the text file.


Switching to File.applicationStorageDirectory fixed the issue for me, though it is far more difficult for a user to find that location.