• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

More FileIO commands

Those are the highlights of FileIO in a nutshell. As you can see from the interface documentation, several other intriguing capabilities exist. You might want to experiment with them, using the same syntax as described here and taking care to dispose of the objects when you're done. Here are some useful hints:

  • You can read (or write) a file one piece at a time. For example, you can read only a single character from the file, using readChar.

  • Consider the concept of the current position in an open file. When you first open the file, the current position is 0, the start of the file (actually, before the start). If you issue a readChar command, it returns the character following the current position (in this case, the first character). The current position is then moved to the next position, and another call to readChar will read the next character (not the same one again). In this manner, you could step through a file, reading it one character at a time.

  • The getPosition command tells you the current position in the file. The setPosition command allows you to move to a specific location.

  • Often you will want to append text to the end of a file. The getLength command tells you the number of characters in the file—a number you can then use with setPosition:

    scribe.setPosition(scribe.getLength())
    

    Writing to the file will now place the new contents at the end of the file.

  • If you want the movie's user to determine where to place the file, the FileIO Xtra can simplify that process. The displayOpen command will cause a standard Open dialog box to pop up. When the user clicks the Open button, the file name (including the path) is returned. The file isn't actually opened at this point; you need to handle that with the openFile command. The displaySave command performs the same function except that it pops up a Save dialog box instead of an Open dialog box.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint