Posted By

allnatural on 12/20/09


Tagged

files FileSystem AIR


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

tonilopez
iamgowan
donaldleegraham


Access file on FileSystem


 / Published in: ActionScript 3
 

URL: http://www.destroyyourcomputer.com

Read a file from the FileSystem

  1. private var file : File;
  2. private var fileStream : FileStream;
  3. private var fileContents : String;
  4. private const ISO_CS : String = "iso-8859-1";
  5.  
  6. private function init() : void
  7. {
  8. file = new File();
  9. file = File.applicationDirectory.resolvePath("file.txt");
  10. fileStream = new FileStream();
  11. fileStream.addEventListener( Event.COMPLETE, fileComplete );
  12. fileStream.openAsync( file, FileMode.READ );
  13. }
  14. private function fileComplete( event : Event ):void
  15. {
  16. fileContents = fileStream.readMultiByte( fileStream.bytesAvailable, ISO_CS );
  17. trace( "fileContents="+fileContents );
  18. }

Report this snippet  

You need to login to post a comment.