在Linux上存储应用程序数据(非特定于用户)的位置 [英] Where to store application data (non-user specific) on Linux

查看:450
本文介绍了在Linux上存储应用程序数据(非特定于用户)的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的基于OSGi的Java应用程序中,我正在开发一个包,为系统的其余部分提供对文件系统的访问。除了提供对用户主目录的访问之外,我还希望提供对非用户特定区域的访问。确切地说这个区域将用于什么尚未确定,但它不适用于首选项(由不同的包处理),但它可能用于存储可能在运行时更改的数据。

In my OSGi-based Java app I am developing a bundle to provide the rest of the system with access to the file system. In addition to providing access to the user home directory, I also wish to provide access to a non-user specific area. Exactly what this area will be used for is as yet undetermined, but it will not be for preferences (handled by a different bundle), however it may be used to store data that could change at runtime.

我打算为此目的使用以下目录:

I intend on using the following directories for this purpose:


  • Windows Vista& Windows 7:\ ProgramData。

  • Windows XP:\Documents and Settings \ All Users。

  • Mac OS X: / Library / Application Support。

Linux中哪一个是合理的等价物,我如何从Java中获取它的句柄代码?

Where is a sensible equivalent in Linux and how do I get a handle on it from my Java code?

推荐答案

这取决于您计划存储的数据类型。这个答案的前提是你在运行时存储和修改数据。

It depends on what kind of data you're planning on storing. This answer is under the premise that you're storing and modifying data at runtime.

与其他人的建议相反,我建议不要使用 / usr / share 用于存储。来自文件系统层次结构标准

Contrary to what others have suggested, I would recommend against using /usr/share for storage. From the Filesystem Hierarchy Standard:


/ usr / share层次结构适用于所有
只读架构独立的
数据文件。

The /usr/share hierarchy is for all read-only architecture independent data files.

当您修改数据时,这违反了 / usr 子系统的只读性质。

As you're modifying data, this goes against the read-only nature of the /usr subsystem.

存储应用程序状态数据的一个看似更好的地方是 / var ,或者更具体地说,的/ var / lib中。这也来自层次结构标准。您可以创建 / var / lib / myapp ,或者如果您还使用锁定文件或日志等内容,则可以利用 / var /锁定 / var / log

A seemingly better place to store your application state data would be /var, or more specifically, /var/lib. This also comes from the Hierarchy Standard. You could create a /var/lib/myapp, or if you're also using things like lock files or logs, you could leverage /var/lock or /var/log.

深入了解标准一个整体(链接到上面) - 你可能会找到一个适合你想要做的更好的地方。

Have a deeper look at the standard as a whole (linked to above) - you might find a place that fits what you want to do even better.

Steve K ,我还建议使用Preferences API来获取应用程序首选项数据。

Like Steve K, I would also recommend using the Preferences API for application preference data.

这篇关于在Linux上存储应用程序数据(非特定于用户)的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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