This chapter describes solutions to common tasks in Apollo applications. The solutions in this chapter illustrate many concepts described in previous chapters, and it provides working MXML code that you can test using Flex Builder or the Apollo SDK.
Apollo lets you access the file system on the user’s computer. This section of the cookbook shows some solutions to common tasks when working with the file system.
For a conceptual overview of the Apollo file system capabilities, see “Accessing the File System.”
You want to synchronously write data from an ActionScript
String object to a text file.
Call an appropriate write method, such as
writeUTF( ), of a FileStream object.
This example uses a
File object named
file, which represents a test.txt file in the Apollo Test subdirectory of the user’s documents directory:
var file:File = File.documentsDirectory file = file.resolve("Apollo Test/test.txt");
For more information, see “Accessing the File System.”
FileStream class is used to open, read, write, and close files. You pass a
fileMode parameter to the
open( ) method (or to the
openAsync( ) method, if you want the operation to occur asyncronously) to specify the capabilities of the
FileStream object. In this case,
FileMode.WRITE provides write access to the file:
var stream:FileStream = new FileStream( ) stream.open(file, FileMode.WRITE);