Flash
  Home arrow Flash arrow Page 2 - 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 
JMSL Numerical Library 
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 - Copying and Moving Files and Directories


    (Page 2 of 5 )

    The File.copyTo() andFile.moveTo()methods copy or move a file or directory to a specified new location. For example, the following code copies the test.txt file in the Apollo Test subdirectory of the user’s documents directory to the User Data subdirectory of the application storage directory:

      var file1:File = File.documentsDirectory.resolve("Apollo
      Test/test.txt");
      var destination:File = File.appStorageDirectory.
      resolve("User Data");
      destination.createDirectory();
      var file2:File = destination.resolve("test.txt");
      file1.copyTo(file2);

    Note the call to theFile.createDirectory()method, which ensures that the destination directory exists.

    The following code moves the Apollo Test 1 subdirectory of the user’s documents directory to the Apollo Test 2 subdirectory (effectively renaming the directory):

      var dir1:File = File.documentsDirectory;
      dir1 = dir1.resolve("Apollo Test 1");
      var dir2:File = File.documentsDirectory;
      dir2 = dir2.resolve("Apollo Test 2");

    You might want to use the asynchronous versions of these methods,File.copyToAsync()andFile.moveToAsync(), if the copy or move operation could take a long time.

    Each of these methods includes aclobber parameter, which you can set totrueto have the operation overwrite existing files. By default, this parameter is set tofalse.

    Creating Files and Directories

    The File.createTempFile() and File.createTempDirectory()static methods of theFileclass let you create a temporary file or directory. Apollo ensures that the temporary file or directory created by these methods is new and unique. For example, the following code creates a temporary file:

      var bufferStorage:File = File.createTempFile();

    Temporary files and directories are not automatically deleted when you close an Apollo application. You will generally want to delete temporary files and directories before closing the application. See the next section, “Deleting Files and Directories,” for more details.

    TheFile.createDirectory()method lets you create a directory in the location specified by theFileobject:

      var directory = File.documentsDirectory;
      directory = directory.resolve("ApolloTest");

    When you open aFileStreamobject with write capabilities then directories are created automatically, if needed. For more information aboutFileStreamobjects, see "Reading and Writing Files" later in this chapter.

    Deleting Files and Directories

    The File.deleteFile() method permanently deletes a file, and the File.deleteDirectory()method permanently deletes a directory. TheFile.moveToTrash()method lets you move a file or directory to the system trash.

    Each of these methods also has an asynchronous counterpart.

    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 2 hosted by Hostway
    Stay green...Green IT