保存更复杂的应用程序数据

发布于 2024-09-30 15:38:16 字数 219 浏览 3 评论 0原文

对于需要保存的简单程序数据,我之前只使用过属性文件,但我想知道如何保存更复杂的应用程序数据,例如:数组列表。

我如何将这些数据保存到文件中?有没有办法将其保存在具有我自己的扩展名的文件中(例如,当使用属性方法保存数据时,不是 .properties )并确保它不能由用户手动编辑(这可以使用记事本进行编辑) .properties 文件的示例)?

提前致谢。

此致, 斯凯夫。

For simple program data that needed to be saved I just used properties files before but I was wondering how I can save more complicated application data such as: arraylists e.g..

How would I save such data into a file? And is there a way to save it in a file with my own extension ( so not .properties for example when using the properties method to save data ) and to make sure it cannot be edited by user manually ( which is simply possible with notepad for example for .properties files )?

Thanks in advance.

Best Regards,
Skyfe.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

無心 2024-10-07 15:38:16

序列化为 XML,在持久化之前对数据进行编码/加密,然后在从应用程序中使用数据时对数据进行解码/解密。

Serialize to XML, encode/encrypt the data prior to persisting, and then decode/decrypt the data when consuming from your app.

时光暖心i 2024-10-07 15:38:16

如前所述,执行此操作的最简单方法是使用内置序列化机制。只需使用包裹在 FileOutputStream 周围的 ObjectOutputStream 将 ArrayList 序列化为文件即可。只要列表中的每个项目都是可序列化的,这就可以正常工作。

修改并非不可能,但它对于文本文件(对于初学者来说是二进制文件)来说相当混乱。

The simplest way to do this as stated is to use the built-in Serialization mechanism. Just serialize your ArrayList out to a file using an ObjectOutputStream wrapped around a FileOutputStream. As long as each item in your list is serializable, this will work fine.

It's not impossible to modify, but it's fairly obfuscated over, say, a text file (it's binary for starters).

时光瘦了 2024-10-07 15:38:16

您可以使用独立的数据库,例如 SQLite

You can use a self contained database like SQLite

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文