diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java new file mode 100644 index 0000000000..20951dc7eb --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryTest.java @@ -0,0 +1,42 @@ +package com.baeldung.resourcedirectory; + +import org.junit.Test; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class ReadResourceDirectoryTest { + + @Test + public void shouldReadResourceAbsolutePathWithFile() { + String path = "src/test/resources"; + + File file = new File(path); + String absolutePath = file.getAbsolutePath(); + + System.out.println(absolutePath); + } + + @Test + public void shouldReadResourceAbsolutePathWithResources() { + String resourceName = "example_resource.txt"; + + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(resourceName).getFile()); + String absolutePath = file.getAbsolutePath(); + + System.out.println(absolutePath); + } + + @Test + public void shouldReadResourceAbsolutePathWithPaths() { + Path resourceDirectory = Paths.get("src","test","resources"); + + String absolutePath = resourceDirectory.toFile().getAbsolutePath(); + + System.out.println(absolutePath); + } + + +} diff --git a/testing-modules/junit-5/src/test/resources/example_resource.txt b/testing-modules/junit-5/src/test/resources/example_resource.txt new file mode 100644 index 0000000000..e69de29bb2