PDA

View Full Version : File Stream Issues...


Chortlez
04-25-2011, 08:09 AM
I'm having problem creating/appending a text file using AIR 2.0 in flash CS5. I use the following code to create an external .txt file

sbox.savebtn.addEventListener(MouseEvent.CLICK, savePath);
function savePath(event:MouseEvent):void
{
var dbFile:File = File.applicationStorageDirectory.resolvePath("db.txt");
var dbStream:FileStream = new FileStream();
dbStream.open(dbFile, FileMode.WRITE);
dbStream.writeUTF("I like pie");
dbStream.close();

}

This code doesn't write a text file and I can't see why as it doesn't throw and error either. Driving me nuts! Any help would be awesome.

SDragon029
04-28-2011, 06:51 PM
Alright so I tested your coding and it is working as it should except for the fact I don't think it's saving the file to the directory your expecting it to save it too no matter if your testing from within the flash debugger or if your testing from an installed version of it. The location I am getting for the file is "C:\Users\Tim\AppData\Roaming\FileSave\Local Store\db.txt" on my system. AppData is usually a hidden folder so unless your viewing hidden folders you wouldn't normally see it.

So unless you want the file to stay there your going to have to re-work the path for the file to be saved. I'd say just hard code a path in but that's generally considered bad coding practice. What I typically do when I am saving files is for the directory I usually have the save dialogue window pop up (such as what you see in word or notepad when you click on save) so they can choose where to save the file. Other than that your code works perfectly.

Cheers,
Tim