开发者

How to write Config file to prevent Hard reboot issues?

开发者 https://www.devze.com 2023-04-05 13:59 出处:网络
I have an application and want to save some config setting from a embedded system (iphone, android, etc)

I have an application and want to save some config setting from a embedded system (iphone, android, etc)

However, I开发者_JS百科 am not going to use DB to save my configuration setting. I am going to write the setting into the file, maybe using json, xml format whatever.

This come a problem that the setting maybe not exactly write into the hard disk all the time, sometimes, it would write into file system cache first. Therefore, if a user make some settings on my application and suddenly got hard reboot due to electric failure, the settings does not really save.

My question is how can that settings make sure write into file inside harddisk if the write operation is already performed in the CODE level?


I cannot speak for iPhone (pro tip: use separate questions for separate operating systems). For Android, you will want to sync your files, as described in this Google blog post. Just be sure to do this I/O on a background thread -- as the blog post indicates:

When you...force the data onto storage, that can be slow; worse, unpredictably slow.

0

精彩评论

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