【问题标题】:reading text files in Adobe AIR在 Adob​​e AIR 中读取文本文件
【发布时间】:2011-12-13 08:58:27
【问题描述】:

最近我发现并非所有文本 (.txt) 文件都可以在 adobe air 中按我的需要读取。由于 diff 文件编码(unicode、utf-8、ascii)。 例如:

 var fDataStream:FileStream;
 var textfile:File = new File ("C:\myfile.txt");
 var sContent:String;
 fDataStream = new FileStream();
 fDataStream.open(textfile,FileMode.READ);
 sContent = fDataStream.readUTFBytes(fDataStream.bytesAvailable);
 fDataStream.close ();

如果“myfile.txt”不是 utf-8 编码的,那么我会得到类似“ÿþE”的字符串 我知道有 fDataStream.readMultyBytes() 方法,但它需要表示事先无法知道的文件字符集的字符串(应用程序的输入 .txt 文件可能在 diff 字符集中)。我没主意了。 谢谢。

【问题讨论】:

    标签: file text air


    【解决方案1】:

    我认为您想使用 .readbytes 而不是 .readUTFBytes

    这应该加载你给它的任何东西。

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html#readBytes()

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 2010-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多