1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Add FileUtils.maybeDeleteFileOrThrow(File)

This commit is contained in:
Florian Schmaus 2018-08-17 12:27:31 +02:00
parent affdcb0557
commit a70ae7ab8e
4 changed files with 15 additions and 25 deletions

View file

@ -196,4 +196,15 @@ public final class FileUtils {
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found.");
}
}
public static void maybeDeleteFileOrThrow(File file) throws IOException {
if (!file.exists()) {
return;
}
boolean successfullyDeleted = file.delete();
if (!successfullyDeleted) {
throw new IOException("Could not delete file " + file);
}
}
}