Close the stream safely

This commit is contained in:
libraryaddict 2014-04-05 03:47:33 +13:00
parent 9a4a9b9845
commit 2879834a7e

View File

@ -41,17 +41,25 @@ public class LibsDisguises extends JavaPlugin {
saveDefaultConfig();
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
boolean needToSaveConfig = false;
InputStream stream = null;
try {
InputStream stream = getClassLoader().getResource("config.yml").openStream();
stream = getClassLoader().getResource("config.yml").openStream();
for (String option : YamlConfiguration.loadConfiguration(stream).getKeys(false)) {
if (!config.contains(option)) {
config.set(option, getConfig().get(option));
needToSaveConfig = true;
}
}
stream.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (needToSaveConfig) {
try {