Reading the text file line by line and push to an array in AS3

前端 未结 6 1266
深忆病人
深忆病人 2020-12-16 19:05

I need some code in AS3 that will read a text file line by line and insert it into an array. Is this possible without having any special character?

sample.tx

6条回答
  •  情书的邮戳
    2020-12-16 19:42

    Here is an example of loading and reading different file types with ActionScript 3:

          import flash.filesystem.FileMode;
          import flash.filesystem.FileStream;
          import flash.filesystem.File;
    
          var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
          myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
    
          var fileStream:FileStream = new FileStream(); // Create our file stream
          fileStream.open(myFile, FileMode.READ);
    
          var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable); // Read the contens of the 
          fileContents_txt.text = fileContents; // Display the contents. I've created a TextArea on the stage for display
    
          fileStream.close(); // Clean up and close the file stream
    

    After reading the string, you can use the int.valueOf() to convert the string to the integer.

提交回复
热议问题