在Java应用程序中保存数据的最佳方法? [英] Best way to save data in a Java application?
问题描述
我正在尝试找到保存简单应用程序状态的最佳方法.从数据库的角度来看,有4/5个表带有日期字段和偏离关系的表.
I'm trying to find the best way to save the state of a simple application. From a DB point-of-view there are 4/5 tables with date fields and relationships off course.
因为该应用程序很简单,并且我希望用户可以选择移动数据(usb笔,dropbox等),所以我希望将所有数据放在一个文件中.
Because the app is simple, and I want the user to have the option of moving the data around (usb pen, dropbox, etc), I wanted to put all data in a single file.
执行此操作的最佳方法/库是什么?
What is the best way/lib to do this?
XML通常是实现此目的的最佳格式(可读性和开放性),但是如果不执行SAX/DOM,我没有找到任何出色的库.
XML usually is the best format for this (readability & openness), but I haven't found any great lib for this without doing SAX/DOM.
推荐答案
如果要使用XML,请查看两分钟教程" .
If you want to use XML, take a look at XStream for simple serialization of Java objects into XML. Here is "Two minute tutorial".
如果您希望简单一些,则标准 Java属性格式也是一种方法存储/加载一些小数据.
If you want something simple, standard Java Properties format can be also a way to store/load some small data.
这篇关于在Java应用程序中保存数据的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!