在 Java 中存储应用程序的 conf 数据的正确方法是什么? [英] What is the proper way to store app's conf data in Java?

查看:24
本文介绍了在 Java 中存储应用程序的 conf 数据的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您在哪里存储 J2SE 应用程序的用户特定机器特定运行时配置数据?

Where do you store user-specific and machine-specific runtime configuration data for J2SE application?

(例如,Windows 上的 C:UsersUSERNAMEAppDataRoaming</em> 和 Unix 上的/home/username)

(For example, C:UsersUSERNAMEAppDataRoaming</em> on Windows and /home/username on Unix)

如何以独立于平台的方式在文件系统中获取这些位置?

How do you get these locations in the filesystem in platform-independent way?

推荐答案

这取决于您的 J2SE 应用程序类型:

That depends on your kind of J2SE Application:

  • J2SE 可执行 JAR 文件(很简单):使用 user.home 系统属性 找到 home-dir.然后相应地创建一个子目录(例如 PGP、SVN 等)
  • Java Web Start 提供了非常好的方法来保护属性.始终特定于用户
  • 最后是 Eclipse RCP:在那里,您有了用于用户和配置(不完全确定如何在 Vista 中访问棘手的内容)的工作区(也源自 user.home)的概念,以供计算机广泛使用
  • J2SE executable JAR file (very simple): use user.home System property to find home-dir. Then make a subdir accordingly (like e.g. PGP, SVN, ... do)
  • Java Web Start provides very nice included methods to safe properties. Always user-specific
  • Finally Eclipse RCP: There you have the notion of the workspace (also derived from user.home) for users and configuration (not totally sure how to access that tricky in Vista) for computer wide usage

所有这些方法,在小心使用时——使用正确的separatorChar -- 操作系统中立.

All these approaches are, when used with care -- use correct separatorChar -- OS neutral.

这篇关于在 Java 中存储应用程序的 conf 数据的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆