Flex 4 中可以进行二进制文件输入和输出吗?
我想编写一个日志系统来记录错误,但我希望文件的格式是二进制的。您可以在 Flex 4 中写入和/或读取二进制文件吗? (更准确地说是动作脚本)
I want to write a logging system to log errors but I want the format of the file to be binary. Can you write and/or read binary files in Flex 4? (actionscript to be more precise)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用 ByteArray 类编写二进制文件,并使用 FileReference 类保存它们(您需要以 FP10 为目标)。
例如,要将 XML 文件写入二进制文件,您只需执行以下操作:
要保存它,您可以通过 FileReference API 运行它:
唯一的缺点是必须从用户操作(鼠标单击)调用 FileReference.save() /按下键盘)。查看 AIR 中的 FileStream 类可为您提供更多选择。 FileReference 还可以用于将文件上传到服务器。查看文档以获得更多想法: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html
或者,您可以通过 SharedObject 保存 ByteArray 信息 (http://help.adobe .com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html)没有太多麻烦,或者按照 Flextras 建议进行操作并通过服务器脚本运行它。
ByteArray 文档:http://help.adobe。 com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html
Yep, you can write binary files using the ByteArray class, and save them using the FileReference class (you need to target FP10).
For example, to write an XML file to binary, you simply do:
To save it, you run it through the FileReference API:
The only drawback with this is that FileReference.save() has to be called from a user action (mouse click/keyboard press). Going through the FileStream class in AIR gives you more options. FileReference can also be used to upload files to the server. Check out the docs to get more of an idea: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html
Alternatively, you can save your ByteArray info through a SharedObject (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html) without too much hassle, or do it as Flextras suggested and run it through a server script.
ByteArray docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html
一般来说,基于 Flex Web 的应用程序写入或读取计算机本地文件的能力非常有限。如果您使用 AIR,则可以使用 文件API 和FileStream API。应该可以用它来读/写二进制文件。
如果您正在构建基于网络的应用程序;然后你可以将数据发送到服务器,并让其保存文件。我相信大多数应用服务器应该支持二进制文件的读写。
Generally, a Flex web based app has very limited ability to write or read files that are local to a machine. If you're using AIR you can use the File API and the FileStream API. It should be possible to read/write binary files with that.
If you're building a web based app; then you can send data to the server, and let that save files. I believe most application servers should support reading and writing of binary files.