0

I want a simple file format to store and retrieve data from disk in Java.

name=value
list=value1,value2,value3

this is mostly going to be used for initial config settings used at startup of the app. I could invision having a watcher on the file to notify the app if it changes so the new settings can be applied potentially but that would be a nice to have. The first part would be pretty easy to write. I just don't want to reinvent the wheel if something is already out there for this and I'd prefer to avoid something as heavy as spring.

3 Answers 3

1

Take a look at the java.util.Properties class.

Properties

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah that works alright if you handle the list parsing yourself and of course there's no notification of anything changing on disk. Just not that rich feature wise.
As I was thinking about this more, there's also the Apache Commons Configuration project. I'm not sure it's that active any more, but you should take a look and see if it meets your needs: commons.apache.org/configuration/index.html
0

You can use the Preferences class. It has a notification system, but alas it doesn't notice changes made outside the running JVM or directly to the underlying configuration store (e.g. the config file). It's a really nice class though.

2 Comments

yeah that is too bad, as I imagine the changes would almost always be outside the JVM.
You can probably add a file watcher thing as well, that would be cool. You can notify the existing preference listeners, so you could reuse those classes.
0

Have a look at OWNER API.

It incorporates most of the feature of java.util.Properties and adds more.

Version 1.0.4 is under development and it will have:

  • support for arrays and collections (list, set, arrays). It is already implemented on master branch.

  • "hot reload", when you change the file the config object gets reloaded (it can be synchronous or asynchronous and it does support event notification for reload). Already implemented in master branch.

  • a lot of features (variable expansion, type conversion). Available since version 1.0.3 and available on maven central repository.

  • Also for 1.0.4 is planned a validation mechanism that will check the file to be compliant before discarding the old content of the config file during the reload. (not implemented yet)

If you need some particular feature, just ask on github issues or become a contributor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.