3 Replies Latest reply on Apr 3, 2008 3:23 PM by Oliver Goldman

    Reading a binary file to string variable does not populate correctly

    TexMags
      Hi, I am new to Adobe Air/Flex and I'm trying to read a binary file which also contains text in "cleartext". The problem I'm having is that when I call FileStream.readUTFBytes method, only the first 6 characters are showing up in my string variable "contents" when I debug it in FlexBuilder or use a trace command and debug it. I have also tried with other types of files but I have a similar problem unless it's a non-binary file.

      Am I doing something incorrectly or should I be reading a binary file differently than the way I'm reading it currently?
      The source code is shown below.

      TIA,
      Magnus

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      import flash.filesystem.File;

      private function readFiles():void{

      var feedFile:File = File.userDirectory.resolvePath( "Local Settings/Application Data/Microsoft/Feeds/AppScout~.feed-ms" );

      var stream:FileStream = new FileStream();
      stream.open( feedFile, FileMode.READ );

      var contents:String = stream.readUTFBytes(stream.bytesAvailable);
      trace(contents);
      stream.close();
      }

      ]]>
      </mx:Script>
      <mx:Button x="121" y="66" label="Button" click="readFiles()" />
      </mx:WindowedApplication>