diff --git a/duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java b/duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java index 7ed235a7..23087d88 100644 --- a/duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java +++ b/duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; import no.priv.garshol.duke.DukeException; @@ -37,17 +38,7 @@ public static File createTempDirectory(String prefix) { File temp = null; try { - temp = File.createTempFile(prefix != null ? prefix : "temp", Long.toString(System.nanoTime())); - - if (!(temp.delete())) { - throw new IOException("Could not delete temp file: " - + temp.getAbsolutePath()); - } - - if (!(temp.mkdir())) { - throw new IOException("Could not create temp directory: " - + temp.getAbsolutePath()); - } + temp = Files.createTempDirectory(prefix != null ? prefix : "temp" + Long.toString(System.nanoTime())).toFile(); } catch (IOException e) { throw new DukeException("Unable to create temporary directory with prefix " + prefix, e); }