Saving files in Application directory?

Questions regarding AIR and Flex.

Saving files in Application directory?

Postby ares623 » Sat Apr 25, 2009 12:55 am

how do I save a file into the application install directory, so that I can open/load it again after the app is closed?
I mean, where do I save it during debugging and releasing?
ares623
 
Posts: 8
Joined: Thu May 22, 2008 3:14 pm

Re: Saving files in Application directory?

Postby iBrent » Sat Apr 25, 2009 2:51 am

Hi,

There are a number of directories you can access using the File class in AIR. Check out this documentation for more info. --> http://livedocs.adobe.com/flash/9.0/Act ... /File.html

Basically there's the applicationDirectory, applicationStorageDirectory, desktopDirectory, and documentsDirectory. These will trace out to the OS specific directories.

Good luck!

iBrent
_________________________

Ask iBrent

Image

Image
User avatar
iBrent
Site Admin
 
Posts: 1004
Joined: Mon Mar 13, 2006 4:37 pm
Location: Utah, USA
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: Saving files in Application directory?

Postby D4G » Sat Apr 25, 2009 11:01 pm

ares623 wrote:how do I save a file into the application install directory, so that I can open/load it again after the app is closed?
I mean, where do I save it during debugging and releasing?


Just to let you know you can not write a file to the application directory. This is a security feature adobe put in. Instead use the ApplicationStorageDirectory if you do not want your user seeing the files created. If you want them to see the files however I would suggest the documentsDirectory or give the user the option to choose the location using a save dialog box.

Location of the applicationStorageDirectory for Windows XP: C:\Documents and Settings\(User)\Application Data\(Applcation Folder)
D4G
 
Posts: 17
Joined: Mon Aug 28, 2006 1:36 am
Flash Version: Adobe Flash CS5.5
Authoring Environment: Microsoft Windows

Re: Saving files in Application directory?

Postby ares623 » Sun Apr 26, 2009 12:20 am

thanks!
but i'm having trouble writing to the file..

here is my code
Code: Select all
var saveFile:File = File.applicationStorageDirectory;
saveFile.resolvePath("colors.txt");

trace(saveFile.exists); //traces 'true'

var writer:FileStream = new FileStream();
writer.open(saveFile, FileMode.WRITE);  //error here

I get a "Error #3006: Not a file." error..
ares623
 
Posts: 8
Joined: Thu May 22, 2008 3:14 pm

Re: Saving files in Application directory?

Postby D4G » Sun Apr 26, 2009 2:42 am

Haha I was writing a post saying I didnt know why you were getting that error but then it hit me. What wouldnt be a file ... A folder! That is what it is doing it is trying to open the folder as a file and clearly this wont do. Corrected code below.

Code: Select all
saveFile = saveFile.resolvePath("colors.txt");

Though may I suggest that you combine lines 1 and 2 into one line. It should look like this.

Code: Select all
var saveFile:File = File.applicationStorageDirectory.resolvePath("colors.txt");


Well good luck
D4G
 
Posts: 17
Joined: Mon Aug 28, 2006 1:36 am
Flash Version: Adobe Flash CS5.5
Authoring Environment: Microsoft Windows

Re: Saving files in Application directory?

Postby ares623 » Sun Apr 26, 2009 6:19 am

Now I have another problem.. :?
When my app starts, it reads from the file I created.. no problem there.
After reading, I close the file by calling
Code: Select all
fileStream.close()


When my app closes, I try to overwrite my file. I get a "Error #3013: File or directory is in use."
Code: Select all
var saveFile:File = File.documentsDirectory;
saveFile = saveFile.resolvePath("colors.txt");
fileStream.open(saveFile, FileMode.WRITE);

But I've already closed the file.. I've tried closing the filestream again before opening for writing (closing it twice). I've also tried reinstantiating the FileStream instance. Still not working.
ares623
 
Posts: 8
Joined: Thu May 22, 2008 3:14 pm

Re: Saving files in Application directory?

Postby ares623 » Sun Apr 26, 2009 8:14 am

seems to be working now.. don't know what happened.
ares623
 
Posts: 8
Joined: Thu May 22, 2008 3:14 pm

Re: Saving files in Application directory?

Postby ebrentnelson » Wed Aug 05, 2009 5:03 pm

Any idea why this started working for you again? I am running into the same problem. Weird thing is that it happens even when I restart my app. It's gotta be something in my routine logic (where I am reading the file and for some reason it isn't closing its stream...)

Thanks.
ebrentnelson
 
Posts: 1
Joined: Wed Aug 05, 2009 4:59 pm
Flash Version: Adobe Flash CS5

Re: Saving files in Application directory?

Postby cmbarsotti » Mon Aug 24, 2009 6:30 pm

ares623: I'd also be interested if you figure out why this started working. I'm also getting error 3013 and tried the things you tried. I'm not having the same issue as ebrentnelson with it happening when I restart the app.

I am doing openAsync and writeUTFBytes, I see the OUTPUT_PROGRESS and CLOSE event is being thrown but if I try to resave the file I get 3013.
cmbarsotti
 
Posts: 1
Joined: Mon Aug 24, 2009 5:59 pm
Flash Version: Adobe Flash CS5.5

Re: Saving files in Application directory?

Postby Voles » Thu Nov 10, 2011 7:51 pm

@D4G I just registered an account to thank you. So, thank you very much!
Voles
 
Posts: 1
Joined: Thu Nov 10, 2011 7:47 pm
Flash Version: Adobe Flash CS5.5

Re: Saving files in Application directory?

Postby D4G » Tue Nov 15, 2011 9:53 pm

Voles wrote:@D4G I just registered an account to thank you. So, thank you very much!


I'm glad to see that I was able to help you specially on such an old topic.
D4G
 
Posts: 17
Joined: Mon Aug 28, 2006 1:36 am
Flash Version: Adobe Flash CS5.5
Authoring Environment: Microsoft Windows


Return to AIR and Flex

Who is online

Users browsing this forum: No registered users and 1 guest

cron