diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/web/SpringBootMockServletContext.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/web/SpringBootMockServletContext.java index c0693e98950..ec810bac3fd 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/web/SpringBootMockServletContext.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/web/SpringBootMockServletContext.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; import org.springframework.core.io.FileSystemResourceLoader; import org.springframework.core.io.Resource; @@ -93,9 +94,7 @@ public class SpringBootMockServletContext extends MockServletContext { try { if (this.emptyRootDirectory == null) { synchronized (this) { - File tempDirectory = File.createTempFile("spr", "servlet"); - tempDirectory.delete(); - tempDirectory.mkdirs(); + File tempDirectory = Files.createTempDirectory("spr-servlet").toFile(); tempDirectory.deleteOnExit(); this.emptyRootDirectory = tempDirectory; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java index b58a351c74e..fb29b31e091 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java @@ -19,6 +19,7 @@ package org.springframework.boot.web.server; import java.io.File; import java.io.IOException; import java.net.InetAddress; +import java.nio.file.Files; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; @@ -185,9 +186,7 @@ public abstract class AbstractConfigurableWebServerFactory implements Configurab */ protected final File createTempDir(String prefix) { try { - File tempDir = File.createTempFile(prefix + ".", "." + getPort()); - tempDir.delete(); - tempDir.mkdir(); + File tempDir = Files.createTempDirectory(prefix + "." + getPort() + ".").toFile(); tempDir.deleteOnExit(); return tempDir; }