开发者

How to store textual data for my java reminder?

I am making a reminder in java, with a graphical interface, and i'm wondering how should i proceed to store my data. I thought about xml parsing. Like: <item><subitem></subitem></item> Are there different ways to do this? Is it a proper way!?

Thanks.

Edit: I forgot to put

item, s开发者_C百科ubitem, /subitem, /item


Multiple are the ways to store data, as are the way to ask a question. One may think about XMLEncoder/XMLDecoder, one other could use Jackson to save data as JSON (which would be far more text-like). One may even use YAML (although I don't know a good lib to save to YAML from Java).

From my experience, XMLEncoder is the simplest thing to use, as it is included in JDK. It has however the drawback of producing XML in all its verbosity. Jackson, with its binding ability, has some interests if you want to provide user a really text-like output.


XML casts a long shadow over Java, but is a sledgehammer when occasionally you just need to crack a nut. Don't get sucked into some overblown schema when your task is simple.

You have to decide your requirements - do you want your files to be small, human readable, to cope with future changes, different character sets, compatible with other software, easy to decode? Don't add requirements because you feel you ought to - what does your software need to work?

As it is, you could just use a simple file format that puts name/value pairs on separate lines, and starts a new reminder with a particular token. This is easy to encode/decode with no unnecessary additional libraries, is relatively easy to read and debug and can cope with future changes.

Remember to write a clean API to get and store reminders, hiding the encoding from the rest of the software. That will allow you to change your format if you suddenly decide it must fit some new requirement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜