如何将文件写入 Eclipse 中的首选项存储

How to write a file into preference store in Eclipse

我想将 CSS 文件写入首选项存储而不是本地文件路径,并在需要时读回。

我是 Eclipse 的新手,一个例子对我很有帮助...

首选项存储用于 键值对,不适用于文件。

Eclipse Preferences - Tutorial

偏好存储适用于使用 'key' 和 'value' 存储的相当小的值。您可以将文件的内容作为 'value' 放置,但这可能不是对商店的良好利用。

Eclipse 插件可以使用'state location' 来保存文件。使用类似:

Bundle bundle = FrameworkUtil.getBundle(getClass());

IPath path = Platform.getStateLocation(bundle);

File dir = path.toFile();

获取状态位置目录的路径。您的插件可以在此目录中存储任何它喜欢的东西,

Platformorg.eclipse.core.runtime.Platform