AIR lets us build applications that work with the file system. Using the classes provided by the Adobe® AIR™ file system API, you can access the host’s file system — reading, managing, creating, and deleting directories and files, writing data to files, and more. I’ve broken working with the file system down into three parts of AIR file operations:
- AIR file basics (below)
- Using the File object to work with files and directories
- Using the FileStream object to read and write files
Language reference for the relevant classes
Now on to part one of AIR file operations:
AIR file basics
AIR provides classes you can use to access, create, and manage files and directories. They live in the flash.filesystem package, and there are three of them:
Class
Description
File
A File object represents the path to a file or a directory. You can use a File object to create a pointer to a file or directory so you can act on it.
FileMode
The FileMode class defines the string constant parameters used by the open() and openAsync() methods of the FileStream class. The FileMode parameter of these methods determines what a FileStream object can do once the file is open — writing, reading, appending, and updating.
FileStream
A FileStream object opens a file so you can read and write data. Once you create a File object pointing to a new or existing file, you pass that pointer to a FileStream object, and you can then use the FileStream to open and work with the file’s data.
Some methods in the File class come in both synchronous and asynchronous versions:
- File.copyTo() and File.copyToAsync()
- File.deleteDirectory() and File.deleteDirectoryAsync()
- File.deleteFile() and File.deleteFileAsync()
- File.getDirectoryListing() and File.getDirectoryListingAsync()
- File.moveTo() and File.moveToAsync()
- File.moveToTrash() and File.moveToTrashAsync()
Likewise, FileStream works with data either synchronously or asynchronously, depending on how the FileStream object opens the file: by calling the open() method or the openAsync() method.
An asynchronous operation runs in the background and fires the corresponding event when it finishes or throws an error. Other code can run while these asynchronous operations are working away in the background. To use the asynchronous versions, you have to set up event listeners, calling the appropriate function with the addEventListener() method of the File or FileStream object.
The synchronous versions let you write straightforward code without bothering with event listeners. However, no other code can run while a synchronous method is executing, so important processes — display object rendering and animation playback, for instance — may be paused.
References: http://livedocs.adobe.com/air/1/devappsflash/help.html?content=dg_part_6_1.html(Files and data)