问题
How can I read and write files synchronously, using PhoneGaps Filesystem API? Is there a an synchronous wrapper available?
回答1:
There is no way to access files synchronously through the provided api. Guessing from the way phonegap is implemented i doubt that you can write a plugin to do this synchronously.
回答2:
Because of the way the Java-to-JavaScript bridge on Android works, it is pretty much impossible to do a synchronous implementation of File IO. This is because each Java object in Android that is bound to the JavaScript environment runs on its own thread.
Use the existing File API available in PhoneGap - but use it asynchronously. Register a callback with it that will notify your app that an IO process is complete.
来源:https://stackoverflow.com/questions/4846949/phonegap-html5-android-synchonous-filesystem-io