Flash
  Home arrow Flash arrow Page 3 - A Closer Look at Apollo`s File System API
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

A Closer Look at Apollo`s File System API
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-03-20

    Table of Contents:
  • A Closer Look at Apollo`s File System API
  • Copying and Moving Files and Directories
  • Reading and Writing Files
  • The open() and openAsync() Methods
  • File Open Modes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Closer Look at Apollo`s File System API - Reading and Writing Files


    (Page 3 of 5 )

    The FileStream class provides methods that let your application read and write files.

    Here’s the general process for reading and writing to a file:

    1. Set up aFile object that points to the file you want to read or write.

      For details, see “Accessing Files and Directories,” earlier in this chapter. 
    2. Instantiate aFileStream object—for example:

         var stream:FileStream = new FileStream();. 
    3. Call theFileStream.open()orFileStream.openAsync()method, passing in theFileobject as thefileparameter and passing an appropriate file mode as thefileModeparameter. For example:

        stream.open(file, FileMode.READ);

      For more information, see “File Open Modes” later in this chapter.
    4. If you called theFileStream.openAsync()method, set up the appropriate event listener functions.

      For more information, see “The open( ) and openAsync( ) Methods,” next.
    5. Call the appropriate read and write method for your data.

      For more information, see “Read and Write Methods” later in this chapter
    6. Close the file, using theFileStream.close()method. For example:

        stream.close();

    Steps 3, 4, and 5 are described in more detail the sections that follow. First, here is a sample of code for reading UTF-8 text from a file synchronously:

      var file:File = File.appStorageDirectory;
      file = file.resolve("settings.xml");
      var stream:FileStream = new FileStream();
      stream.open(file, FileMode.READ);
      var data:String = stream.readUTFBytes(stream.
      bytesAvailable);
      stream.close();

    Here is some code that reads the same data asynchronously:

      var file:File = File.appStorageDirectory;
      file = file.resolve("settings.xml");
      var stream:FileStream = new FileStream();
      stream.openAsync(file, FileMode.READ);
      stream.addEventListener(Event.COMPLETE, readData);
      var data:String;

      private function readData(event:Event):void {
        data = stream.readUTFBytes(stream.bytesAvailable);
        stream.close();
     
    }

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Apollo for Adobe Flex Developer's Pocket...
     

    Buy this book now. This article is excerpted from chapter four of the Apollo for Adobe Flex Developer's Pocket Guide, written by Mike Chambers, Rob Dixon and Jeff Swartz (O'Reilly, 2007; ISBN: 0596513917). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks
    - Building Preloaders






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT