-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathCommentedConfigExample.java
29 lines (26 loc) · 1.12 KB
/
CommentedConfigExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import com.electronwill.nightconfig.toml.TomlWriter;
import java.io.File;
/**
* @author TheElectronWill
*/
public class CommentedConfigExample {
public static void main(String[] args) {
// Creates a CommentedConfig in memory (ie not linked to a file)
CommentedConfig config = CommentedConfig.inMemory();
config.set("key", "value");
config.setComment("key", "This is a comment.");
String comment = config.getComment("key");
System.out.println("Comment of the key: " + comment);
System.out.println("Config: " + config);
/* An non-FileConfig cannot be saved with a save() method, but any config can be saved by
an appropriate ConfigWriter. Here we'll use a TomlWriter to write the config in the TOML
format. */
File configFile = new File("commentedConfig.toml");
TomlWriter writer = new TomlWriter();
writer.write(config, configFile, WritingMode.REPLACE);
/* That's it! The config has been written to the file. Note that there is no need to close
the writer nor to catch any exception. */
}
}