diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md index c4eacdf27a..06a2a5a0fc 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -9,4 +9,5 @@ This module contains articles about core Java input and output (IO) - [Check If a File or Directory Exists in Java](https://www.baeldung.com/java-file-directory-exists) - [Copy a Directory in Java](https://www.baeldung.com/java-copy-directory) - [Java Files Open Options](https://www.baeldung.com/java-file-options) +- [Creating Temporary Directories in Java](https://www.baeldung.com/java-temp-directories) - [[<-- Prev]](/core-java-modules/core-java-io-2) diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java index a44aea1383..7f7936494f 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java @@ -4,6 +4,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -20,8 +21,8 @@ public class DirectoryEmptinessUnitTest { } @Test - public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException { - Path aFile = Paths.get(getClass().getResource("/notDir.txt").getPath()); + public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException, URISyntaxException { + Path aFile = Paths.get(getClass().getResource("/notDir.txt").toURI()); assertThat(isEmpty(aFile)).isFalse(); } diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java index 470e06ef96..5cf7d88cd6 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java @@ -4,6 +4,7 @@ import org.apache.commons.io.FileUtils; import org.junit.Test; import java.io.IOException; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -66,10 +67,16 @@ public class TemporaryDirectoriesUnitTest { @Test public void givenTempDirWithPrefixWithFileAttrs_whenCreatePlainJava_thenAttributesAreSet() throws IOException { - final FileAttribute> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--------")); + boolean isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); - final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix", attrs); - assertThat(tmpdir.toFile().getPath()).startsWith("target"); - assertThat(tmpdir.toFile().canWrite()).isFalse(); + if(!isPosix){ + System.out.println("You must be under a Posix Compliant Filesystem to run this test."); + } else { + final FileAttribute> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--------")); + + final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix", attrs); + assertThat(tmpdir.toFile().getPath()).startsWith("target"); + assertThat(tmpdir.toFile().canWrite()).isFalse(); + } } }