Skip to main content
Participating Frequently
Oct 27, 2011 8:21 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

1 reply

Inspiring
Sep 22, 2015 11:22 PM UTC

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.

Translate