2016-01-06 79 views
0

我有一个Adobe AIR应用程序,用户可以从其文件系统处理文本文件。我一直假设UTF-8,但是在文本文件采用其他编码(例如iso-8859-1或iso-2022-kr)的情况下,我应该如何确定(最好猜测)编码类型文本文件,所以我可以读取到一个字符串的内容?在Adobe AIR中读取未知编码的文本文件

FileStream.readMultiByte支持an intimidating range of types

+0

我可以尝试File.systemCharset,但不能保证该文件是由运行我的应用程序的机器创建的。如果我可以首先确定该文件不是UTF-8,那可能是一个可以接受的后备。 –

+0

这里是关于PHP的mb_detect_encoding的讨论,但AS3没有任何类型(官方或用户编写,我可以找到)http://php.net/manual/en/function.mb-detect-encoding.php –

回答

0

您可以尝试通过查看文件是否具有标题(如BOM)来进行猜测。但你永远不会100%确定。

看看另外一个答案:

How to detect the encoding of a file?

How can I detect the encoding/codepage of a text file

编辑:也许这会被猜测的方法,它是不是在AS3,但它可以帮助:Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.

而且,如果它是您应用程序的一个选项,您可以使用UTF-8并让用户使用他们选择的另一种编码预览文本。

+0

我'将尝试转换并使用链接的C#类来确定UTF-8/16/32/BOM/no-BOM,然后回退到File.systemCharset并让用户从列表中选择编码。伟大的建议 - 谢谢! –