Close the stream safely
This commit is contained in:
parent
9a4a9b9845
commit
2879834a7e
@ -41,17 +41,25 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
||||||
boolean needToSaveConfig = false;
|
boolean needToSaveConfig = false;
|
||||||
|
InputStream stream = null;
|
||||||
try {
|
try {
|
||||||
InputStream stream = getClassLoader().getResource("config.yml").openStream();
|
stream = getClassLoader().getResource("config.yml").openStream();
|
||||||
for (String option : YamlConfiguration.loadConfiguration(stream).getKeys(false)) {
|
for (String option : YamlConfiguration.loadConfiguration(stream).getKeys(false)) {
|
||||||
if (!config.contains(option)) {
|
if (!config.contains(option)) {
|
||||||
config.set(option, getConfig().get(option));
|
config.set(option, getConfig().get(option));
|
||||||
needToSaveConfig = true;
|
needToSaveConfig = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (stream != null) {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (needToSaveConfig) {
|
if (needToSaveConfig) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user