在 Adobe AIR 中读取未知编码的文本文件
Reading unknown-encoded text files in Adobe AIR
我有一个 Adobe AIR 应用程序,用户可以在其中处理来自其文件系统的文本文件。我一直在假设 UTF-8,但如果文本文件采用其他编码(例如 iso-8859-1 或 iso-2022-kr),我应该如何确定(最佳猜测)的编码类型文本文件,以便我可以将内容读入字符串?
FileStream.readMultiByte 支持 an intimidating range of types.
您可以尝试通过查看文件是否有 header 来猜测,例如 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 并让用户以他们选择的另一种编码预览文本。
我有一个 Adobe AIR 应用程序,用户可以在其中处理来自其文件系统的文本文件。我一直在假设 UTF-8,但如果文本文件采用其他编码(例如 iso-8859-1 或 iso-2022-kr),我应该如何确定(最佳猜测)的编码类型文本文件,以便我可以将内容读入字符串?
FileStream.readMultiByte 支持 an intimidating range of types.
您可以尝试通过查看文件是否有 header 来猜测,例如 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 并让用户以他们选择的另一种编码预览文本。