[AIR Only] File system access for reading, writing, and navigating files and directories in Adobe AIR applications.
Represents a path to a file or directory. Extends FileReference (available in Flash Player), adding AIR-specific file system operations.
new File(path:String = null): Creates a File object for the specified native path.
These cross-platform properties point to standard system locations:
applicationDirectory:File: (Read-only) The directory where the AIR application is installed. Do not write to this directory (may invalidate app signature).applicationStorageDirectory:File: A private storage directory unique to the AIR application. Use this for internal app data.applicationRemovableStorageDirectory:File: [Android only] Storage on external/removable media.cacheDirectory:File: [AIR 3.6+] A cache directory for temporary files that may be deleted by the OS.desktopDirectory:File: The user's desktop folder.documentsDirectory:File: The user's documents folder.userDirectory:File: The user's home directory.
separator:String: Platform path separator ("/" on macOS/Linux, "" on Windows).lineEnding:String: Platform line ending ("\n" on macOS/Linux, "\r\n" on Windows).systemCharset:String: Default character encoding for the OS (e.g., "UTF-8", "windows-1252").
nativePath:String: The platform-specific path string (e.g.,C:\Users\...on Windows,/Users/...on macOS).url:String: The file:// URL representation of the path.exists:Boolean: (Read-only)trueif the file or directory exists.isDirectory:Boolean: (Read-only)trueif this is a directory.isHidden:Boolean: (Read-only)trueif hidden by the OS.isPackage:Boolean: (Read-only) [macOS only]trueif the directory is an application package (.app).isSymbolicLink:Boolean: (Read-only)trueif this is a symbolic link.parent:File: (Read-only) The parent directory.nullif at root.spaceAvailable:Number: (Read-only) Available disk space in bytes on the volume containing this path.icon:Array: (Read-only) An array ofBitmapDatarepresenting the file's icon at various sizes.downloaded:Boolean: (Read-only) [AIR 3.5+]trueif the file was downloaded from the Internet (macOS quarantine flag).preventBackup:Boolean: [AIR 3.5+, iOS only] Iftrue, excludes file from iCloud backup.permissionStatus:String: [AIR 25+, Android 6+ only] Permission status for external storage ("granted","denied","unknown").
Returns a new File object for a path relative to this File. Supports .. for parent directory.
var appDir:File = File.applicationDirectory;
var configFile:File = appDir.resolvePath("config/settings.xml");Gets the relative path from referenceFile to this File.
Resolves symbolic links and normalizes the path (removes . and ..).
Creates a copy of the File object.
Returns an array of File objects representing filesystem roots (e.g., C:, D:\ on Windows; / on macOS/Linux).
[AIR 1.5+] Creates a temporary file in the OS temp directory with a unique name.
[AIR 1.5+] Creates a temporary directory in the OS temp directory with a unique name.
Opens native file/folder picker dialogs. These are asynchronous and dispatch events when complete.
Opens a dialog for the user to select a file to open.
Opens a dialog for the user to select multiple files.
Opens a dialog for the user to specify a file path to save.
Opens a dialog for the user to select a directory.
Events:
Event.SELECT: Dispatched when user selects a file/directory.Event.CANCEL: Dispatched when user cancels the dialog.FileListEvent.SELECT_MULTIPLE: Dispatched when user selects multiple files (forbrowseForOpenMultiple).
Type Filter Example:
var imageFilter:FileFilter = new FileFilter("Images", "*.jpg;*.png;*.gif");
var docFilter:FileFilter = new FileFilter("Documents", "*.pdf;*.doc");
file.browseForOpen("Select a file", [imageFilter, docFilter]);Deletes the file synchronously. Throws error if it's a directory or doesn't exist.
Deletes the file asynchronously.
Events: Event.COMPLETE, IOErrorEvent.IO_ERROR
Deletes the directory synchronously. If deleteDirectoryContents = true, removes all contents recursively.
Deletes the directory asynchronously.
Events: Event.COMPLETE, IOErrorEvent.IO_ERROR
Copies file or directory synchronously. If overwrite = false, throws error if destination exists.
Copies file or directory asynchronously.
Events: Event.COMPLETE, IOErrorEvent.IO_ERROR, ProgressEvent.PROGRESS
Moves/renames file or directory synchronously.
Moves/renames file or directory asynchronously.
Events: Event.COMPLETE, IOErrorEvent.IO_ERROR, ProgressEvent.PROGRESS
[AIR 2+] Moves file or directory to OS trash/recycle bin synchronously.
[AIR 2+] Moves file or directory to trash asynchronously.
Events: Event.COMPLETE, IOErrorEvent.IO_ERROR
Creates the directory and any missing parent directories. Does nothing if directory already exists.
Synchronously returns an array of File objects representing directory contents. Throws error if not a directory.
Asynchronously retrieves directory contents.
Events: FileListEvent.DIRECTORY_LISTING (contains files:Array property)
[AIR 1.5+] Opens the file with the OS default application (e.g., opens .txt in Notepad).
Cancels an ongoing async operation (browse, copy, move, delete, directory listing).
[AIR 25+, Android 6+ only] Requests external storage permission if not yet granted.
Events: PermissionEvent.PERMISSION_STATUS
var configFile:File = File.applicationStorageDirectory.resolvePath("config.txt");
if (configFile.exists) {
var stream:FileStream = new FileStream();
stream.open(configFile, FileMode.READ);
var content:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
trace("Config: " + content);
} else {
trace("Config file not found");
}var dir:File = File.documentsDirectory;
dir.addEventListener(FileListEvent.DIRECTORY_LISTING, onListing);
dir.getDirectoryListingAsync();
function onListing(event:FileListEvent):void {
for each (var file:File in event.files) {
trace(file.name + (file.isDirectory ? " [DIR]" : ""));
}
}Used to read and write files. Implements IDataInput and IDataOutput, providing binary and text I/O.
new FileStream(): Creates a FileStream object.
Opens a file synchronously in the specified mode. Blocks until file is ready.
Opens a file asynchronously. Does not block. Listen for events to know when data is ready.
File Modes (see FileMode constants):
READ: Open for reading only.WRITE: Open for writing. Creates file if it doesn't exist. Truncates existing file to 0 bytes.APPEND: Open for writing at the end of file. Creates file if it doesn't exist.UPDATE: Open for reading and writing. Does not truncate. Creates file if it doesn't exist.
bytesAvailable:uint: (Read-only) Number of bytes available to read from the current position.position:Number: Current read/write position in the file (in bytes). Can be set to seek.readAhead:Number: [Async only] Number of bytes to buffer ahead. Default is 4096. Higher values improve performance for sequential reads.endian:String: Byte order for multi-byte reads/writes.Endian.BIG_ENDIANorEndian.LITTLE_ENDIAN. Default isBIG_ENDIAN.objectEncoding:uint: AMF encoding version forreadObject()/writeObject(). UseObjectEncoding.AMF0orObjectEncoding.AMF3.
All read methods are synchronous and read from the internal buffer (check bytesAvailable first).
readBoolean():Boolean: Reads 1 byte as a Boolean.readByte():int: Reads 1 signed byte (-128 to 127).readUnsignedByte():uint: Reads 1 unsigned byte (0 to 255).readShort():int: Reads 2 bytes as signed short (-32768 to 32767).readUnsignedShort():uint: Reads 2 bytes as unsigned short (0 to 65535).readInt():int: Reads 4 bytes as signed int.readUnsignedInt():uint: Reads 4 bytes as unsigned int.readFloat():Number: Reads 4 bytes as IEEE 754 single-precision float.readDouble():Number: Reads 8 bytes as IEEE 754 double-precision float.readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void: Reads bytes into a ByteArray.readUTFBytes(length:uint):String: Reads UTF-8 bytes as a string (length in bytes, not characters).readUTF():String: Reads a UTF-8 string prefixed with a 16-bit length.readMultiByte(length:uint, charSet:String):String: Reads a string in the specified character set.readObject():*: Reads an AMF-encoded object.
All write methods are synchronous (async mode buffers and writes in background).
writeBoolean(value:Boolean):void: Writes 1 byte.writeByte(value:int):void: Writes 1 signed byte.writeShort(value:int):void: Writes 2 bytes.writeInt(value:int):void: Writes 4 bytes.writeUnsignedInt(value:uint):void: Writes 4 bytes.writeFloat(value:Number):void: Writes 4 bytes.writeDouble(value:Number):void: Writes 8 bytes.writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void: Writes bytes from a ByteArray.writeUTFBytes(value:String):void: Writes a UTF-8 string (no length prefix).writeUTF(value:String):void: Writes a UTF-8 string with 16-bit length prefix.writeMultiByte(value:String, charSet:String):void: Writes a string in the specified character set.writeObject(object:*):void: Writes an AMF-encoded object.
Closes the file stream. Always call this when done to release the file handle.
[AIR 1.5+] Truncates the file at the current position. Useful for overwriting part of a file without rewriting the entire file.
Event.OPEN: Dispatched when file is successfully opened.ProgressEvent.PROGRESS: Dispatched as data becomes available for reading or as write buffer is flushed.Event.COMPLETE: Dispatched when all data has been read or written.IOErrorEvent.IO_ERROR: Dispatched on I/O errors.Event.CLOSE: Dispatched when file is closed.
var file:File = File.applicationStorageDirectory.resolvePath("log.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("Hello, AIR!\n");
stream.close();var file:File = File.desktopDirectory.resolvePath("data.bin");
var stream:FileStream = new FileStream();
stream.addEventListener(Event.COMPLETE, onComplete);
stream.openAsync(file, FileMode.READ);
function onComplete(event:Event):void {
var value:int = stream.readInt();
trace("Read value: " + value);
stream.close();
}var logFile:File = File.applicationStorageDirectory.resolvePath("debug.log");
var stream:FileStream = new FileStream();
stream.open(logFile, FileMode.APPEND);
stream.writeUTFBytes(new Date().toString() + ": Application started\n");
stream.close();Constants for file opening modes.
READ:String = "read": Open for reading. File must exist.WRITE:String = "write": Open for writing. Creates file if missing. Truncates to 0 bytes if exists.APPEND:String = "append": Open for writing at end. Creates file if missing. Does not truncate.UPDATE:String = "update": Open for reading and writing. Creates file if missing. Does not truncate. Usepositionto seek.
[AIR 3.4+] Represents a mounted storage volume (hard drive, USB drive, SD card, etc.).
drive:String: (Read-only) Drive letter (Windows only, e.g., "C:").name:String: (Read-only) User-friendly volume name.fileSystemType:String: (Read-only) Type of filesystem (e.g., "NTFS", "FAT32", "HFS+", "ext4").isRemovable:Boolean: (Read-only)trueif the volume is removable (USB, SD card).isWritable:Boolean: (Read-only)trueif the volume is writable.rootDirectory:File: (Read-only) File object pointing to the root of the volume.
getDirectoryListing():Vector.<File>: Returns contents of the root directory.
[AIR 3.4+] Static class for querying available storage volumes.
storageVolumeInfo:StorageVolumeInfo: Singleton instance.
getStorageVolumes():Vector.<StorageVolume>: Returns all currently mounted storage volumes.
StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT: Dispatched when a volume is mounted.StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT: Dispatched when a volume is unmounted.
var volumes:Vector.<StorageVolume> = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
for each (var volume:StorageVolume in volumes) {
trace(volume.name + " (" + volume.drive + ") - " +
(volume.isRemovable ? "Removable" : "Fixed") + " - " +
(volume.isWritable ? "Writable" : "Read-only"));
}- Never write to
applicationDirectory. It may invalidate the app signature and break updates. - Use
applicationStorageDirectoryfor internal app data (preferences, cache, databases). - Use
documentsDirectoryfor user-created files.
- Synchronous: Simpler code, but blocks the UI. Good for small files or quick operations.
- Asynchronous: Non-blocking, but requires event handling. Essential for large files to avoid freezing the UI.
Always wrap file operations in try-catch blocks:
try {
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
// ... read operations
stream.close();
} catch (e:Error) {
trace("File error: " + e.message);
}Always close() FileStream objects when done, even if an error occurs:
var stream:FileStream = new FileStream();
try {
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("data");
} finally {
stream.close(); // Ensures file handle is released
}Use File.resolvePath() and static directory properties instead of hardcoded paths:
// ✅ Good (cross-platform)
var file:File = File.applicationStorageDirectory.resolvePath("data/config.xml");
// ❌ Bad (Windows-only)
var file:File = new File("C:\\Program Files\\MyApp\\config.xml");When reading/writing text, use readUTFBytes() / writeUTFBytes() for UTF-8, or readMultiByte() / writeMultiByte() for other encodings. The systemCharset property provides the OS default encoding.