Access file on FileSystem


/ Published in: ActionScript 3
Save to your folder(s)

Read a file from the FileSystem


Copy this code and paste it in your HTML
  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. }

URL: http://www.destroyyourcomputer.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.