在程序中处理用户设置的最佳方法
我想知道在程序中处理用户设置的最佳方法/实践是什么。我正在编写一个程序,希望允许用户保存设置,这些设置可以在程序启动时自动加载。我不只是要求代码,而是处理的最佳实践,例如如何在运行时处理设置,我是否需要创建一个诸如 UserSettings 之类的对象(我正在使用 Java)?哪种格式最适合保存设置(XML/JSON?)?具有人类可读的文件格式好吗?我应该注意哪些事情?我喜欢听听一些专业的 stackoverflow 用户的想法/建议。
I want to know what are the best ways/practices of handling user settings in a program. I'm writing a program and want to allow users to save settings which can be loaded automatically as soon as the program starts. I'm not just asking for codes, but the best practices of handling such as how to handle the settings at run time, should I need to create an object such as UserSettings (I'm using Java)? Which format is best for saving the settings (XML/JSON?)? Is it good to have the file format human readable? what are the things that I should take care of? I like to hear the thoughts/advices of some professional stackoverflow users out there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
拥有人类可读的格式是很棒的;如果由于某种原因某个设置使程序完全无法使用,则可以进入并将该设置恢复为正常状态。
Having a human-readable format is great; if for some reason a setting makes the program completely unusable it is then possible to go in and frob the setting to something sane.
如果您的用户将从一台计算机漫游到另一台计算机,那么将用户设置存储在数据库或某个集中存储库中是有意义的。
否则,本地保存的、人类可读的 .INI(带有命名部分)或 .XML 文件。
如果使用 .XML 文件,请尽量避免使其过于“密集”,并添加适当的注释。
If your users will roam from computer to computer then having user settings in a database or some centralised repository makes sense.
Otherwise, a locally-saved, human-readable .INI (with named sections) or a .XML file.
If using a .XML file, try to avoid making it too 'dense', and sprinkle with appropriate comments.