开发者

Adobe Air - Read updates to File with FileStream

I'm trying to get two different apps to communicate through a 开发者_开发问答file. I would like app 1 to append some text to a file, and app 2 to notice, and read the new bytes (not the whole file).

There is an event, ProgressEvent.PROGRESS, that is supposed to fire when new data is available on a FileStream, but it only fires when I first open the file.

Basically, I would like to leave the FileStream open, listening like a socket on the end of that file for changes. Is it possible? Any performance considerations?

Thanks1


You can use the FileMonitor class that is part of Adobe's 'as3corelib' package to monitor files.

http://code.google.com/p/as3corelib/

It comes with FileMonitorEvent.CHANGE, MOVE and CREATE events.

Presentation and example here :

http://www.mikechambers.com/blog/2009/03/11/monitoring-file-changes-in-adobe-air/


I'd say keep a record of the filesize, check it periodically with a Timer, and then seek to the end of the old file when it gets bigger. With AIR 2.0 it should be easy, if you embed something akin to "tail -f".


I understand that you probably want the socket-like 'interface' for reading/writing files between two apps, but you may be able to accomplish the same thing with a local SharedObject and a 'manager' class that uses the localConnection class to do certain things to that sharedObject/file. Random thought....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜