read src/test/resources

This commit is contained in:
Kacper Koza 2019-04-18 22:21:35 +02:00
parent 275a4acaea
commit 1263171465
2 changed files with 42 additions and 0 deletions

View File

@ -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);
}
}