Switched to use Files.delete

When File.delete fails, this boolean method simply returns false with no
indication of the cause. On the other hand, when Files.delete fails,
this void method returns one of a series of exception types to better
indicate the cause of the failure. More information is generally better
in a debugging situation, so I'll use this option.
This commit is contained in:
Tastybento 2018-02-07 19:33:59 -08:00
parent 08b2e2579b
commit 29d09922b9

View File

@ -4,10 +4,12 @@ import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -520,9 +522,12 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
File dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
File tableFolder = new File(dataFolder, dataObject.getSimpleName());
if (tableFolder.exists()) {
File file = new File(tableFolder, fileName);
if (!file.delete()) {
plugin.getLogger().severe("Could not delete yaml database object! " + file.getName());
try {
Files.delete(file.toPath());
} catch (IOException e) {
plugin.getLogger().severe("Could not delete yaml database object! " + file.getName() + " - " + e.getMessage());
}
}
}