13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with the file system<br />

Call the close() method of the FileStream object wh<strong>en</strong> you are done working with the file.<br />

Calling the close() method makes the file available to other applications.<br />

For details, see “Initializing a FileStream object, and op<strong>en</strong>ing and closing files” on page 689.<br />

To see a sample application that uses the FileStream class to read and write files, see the following articles at the Adobe<br />

AIR Developer C<strong>en</strong>ter:<br />

Building a text-file editor<br />

Building a text-file editor<br />

Reading and writing from an XML prefer<strong>en</strong>ces file<br />

Working with FileStream objects<br />

Adobe AIR 1.0 and later<br />

The FileStream class defines methods for op<strong>en</strong>ing, reading, and writing files.<br />

FileStream op<strong>en</strong> modes<br />

Adobe AIR 1.0 and later<br />

The op<strong>en</strong>() and op<strong>en</strong>Async() methods of a FileStream object each include a fileMode parameter, which defines<br />

some properties for a file stream, including the following:<br />

The ability to read from the file<br />

The ability to write to the file<br />

Whether data will always be app<strong>en</strong>ded past the <strong>en</strong>d of the file (wh<strong>en</strong> writing)<br />

What to do wh<strong>en</strong> the file does not exist (and wh<strong>en</strong> its par<strong>en</strong>t directories do not exist)<br />

The following are the various file modes (which you can specify as the fileMode parameter of the op<strong>en</strong>() and<br />

op<strong>en</strong>Async() methods):<br />

File mode Description<br />

FileMode.READ Specifies that the file is op<strong>en</strong> for reading only.<br />

FileMode.WRITE Specifies that the file is op<strong>en</strong> for writing. If the file does not exist, it is created wh<strong>en</strong> the FileStream object<br />

is op<strong>en</strong>ed. If the file does exist, any existing data is deleted.<br />

FileMode.APPEND Specifies that the file is op<strong>en</strong> for app<strong>en</strong>ding. The file is created if it does not exist. If the file exists, existing<br />

data is not overwritt<strong>en</strong>, and all writing begins at the <strong>en</strong>d of the file.<br />

FileMode.UPDATE Specifies that the file is op<strong>en</strong> for reading and writing. If the file does not exist, it is created. Specify this<br />

mode for random read/write access to the file. You can read from any position in the file. Wh<strong>en</strong> writing<br />

to the file, only the bytes writt<strong>en</strong> overwrite existing bytes (all other bytes remain unchanged).<br />

Initializing a FileStream object, and op<strong>en</strong>ing and closing files<br />

Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> you op<strong>en</strong> a FileStream object, you make it available to read and write data to a file. You op<strong>en</strong> a FileStream object<br />

by passing a File object to the op<strong>en</strong>() or op<strong>en</strong>Async() method of the FileStream object:<br />

Last updated 6/6/2012<br />

689

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!