问题
AIR in general seems to be storing the xml file in the path where the app is installed. I am generating an xml and I want to save/store a xml file in local asset folder of AIR application.
Any thoughts on doing this.
回答1:
The File class has some static variables that point to local directories:
From the docs:
- File.applicationStorageDirectory — a storage directory unique to each installed AIR application
- File.applicationDirectory — the read-only directory where the application is installed (along with any installed assets)
- File.desktopDirectory — the user's desktop directory
- File.documentsDirectory — the user's documents directory
- File.userDirectory — the user directory
Creating a pointer to the file
Usually you'll want to store files like these in File.applicationStorageDirectory. So to create the file do:
File.applicationStorageDirectory.resolvePath("my-config.xml");
Alternatively, you can let the user choose where to store the file by using File#browseForSave(), which will display a native 'save' window to choose the location.
Writing the content
Open a FileStream for the File in 'write' mode and write an XML string to the file.
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeUTF(myXmlContent);
fs.close();
回答2:
look at http://www.adobe.com/devnet/air/flex/quickstart/articles/xml_prefs.html
http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml-part-2/
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html
var prefsFile:File = File.applicationStorageDirectory;
prefsFile = prefsFile.resolvePath("preferences.xml");
stream = new FileStream();
stream.open(prefsFile, FileMode.WRITE);
stream.writeUTFBytes(outputStringXML);
Or something like:
var saveStr:String = xmlToSave.toXMLString();
var file:File = new File('app-storage:/data.xml');
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeUTFBytes(saveStr);
fs.close();
来源:https://stackoverflow.com/questions/8998058/storing-saving-xml-in-local-asset-folder-in-air