NightConfig is a powerful yet easy-to-use java configuration library, written in Java 8.
It supports the following formats:
- Code examples are available here. Note: these examples are for the last stable version, and may not work with the master branch.
- You can also read the wiki.
// Simple builder:
FileConfig conf = FileConfig.of("the/file/config.toml");
// Advanced builder, default resource, autosave and much more (-> cf the wiki)
CommentedFileConfig config = CommentedFileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
config.load(); // This actually reads the config
String name = config.get("username"); // Generic return type!
List<String> names = config.get("users_list"); // Generic return type!
long id = config.getLong("account.id"); // Compound path: key "id" in subconfig "account"
int points = config.getIntOrElse("account.score", defaultScore); // Default value
config.set("account.score", points*2);
String comment = config.getComment("user");
// NightConfig saves the config's comments (for TOML and HOCON)
// config.save(); not needed here thanks to autosave()
config.close(); // Close the FileConfig once you're done with it :)
NightConfig is built with Gradle. The project is divided in several modules, the "core" module plus one module per supported configuration format.
The releases are available on Maven Central and JitPack.
Older versions of Android don't provide the packages java.util.function
and java.nio.file
, which
NightConfig heavily uses. If you encounter issues on android you can use the special version that
I've made for you by adding _android
to the modules' names.
Please read the wiki for more information.
The repository has several branches:
- Branches of old unmaintened versions: stable-1.x, stable-2.x stable-2.1.x
- Current in-development branch: master