Java源码示例:com.moandjiezana.toml.TomlWriter
示例1
/**
* Write the given config type to a file.
*
* @param configFilePath path to toml file
* @param content type of the config class to be used when de-serializing
* @throws ConfigParserException if cannot write the content to file or specified file does not exist
*/
public static void write(String configFilePath, Object content) throws ConfigParserException {
Path configPath = Paths.get(configFilePath);
if (!Files.exists(configPath)) {
throw new ConfigParserException("Mandatory configuration file '" + configPath + "' does not exists.");
}
TomlWriter tomlWriter = new TomlWriter();
try {
tomlWriter.write(content, new File(configFilePath));
} catch (IOException e) {
throw new ConfigParserException("Cannot write the content to configuration file '" + configPath + "'.",
e);
}
}
示例2
static void store() {
try {
//props.store(new FileOutputStream(erlyberlyConfig), " erlyberly at https://github.com/andytill/erlyberly");
new TomlWriter().write(props, new FileOutputStream(erlyberlyConfig));
}
catch (IOException | NoClassDefFoundError e) {
e.printStackTrace();
}
}
示例3
public static String toToml(Map<String, Object> tomlMap) {
TomlWriter tomlWriter = new TomlWriter();
return tomlWriter.write(tomlMap);
}
示例4
public static String toToml(Object from) {
TomlWriter tomlWriter = new TomlWriter();
return tomlWriter.write(from);
}