DEV Community

Discussion on: How to manage your configuration file with YAML in Java programmatically

Collapse
 
dgolcher profile image
Monet Goldshire

Hey man thanks for the example I've wanted to change the config support I had on an old project from from a properties.config to yaml (no real reason why)
I've been a TPM for the last 6 years so my java dev skills are rusty bear with me.
However I have a couple of questions:
1) Why don't you use Try-with-resources ?
Wouldn't the yaml.load(new FileInputStream(configPath.toFile()));
require an explicit close to prevent the resource to remain open?
2) This example seems to assume an external yml, what if I wanted to have an internal resource with the yml defaults protected from changes on the external file?
getClass().getClassLoader().getResourceAsStream(PATH); ?

Cheers!

Collapse
 
kooin profile image
Kooin-Shin

Thanks for meaningful asking.
I didn't have tried to load or dump on internal resource file yet. so I can't have confidence that able to work on it. In future, I might try it. If anything happens, I will post again. GoodLuck!

Collapse
 
dgolcher profile image
Monet Goldshire

Looking forward to it and cheers from Costa Rica

Thread Thread
 
kooin profile image
Kooin-Shin • Edited

Hi,
A bit while before, I wrote about to be answer of your asking.
It's good to visit below link. GoodLuck!
dev.to/kooin/how-to-handling-inter...

Thread Thread
 
dgolcher profile image
Monet Goldshire

Hey man happy 2021, thanks! I'll compare it to the version I did trying to address the same questions.