Access Resources in Unit Tests
Resource names don't start with a slash, so you'll need to get rid of that. The resource should preferably be read with UnitTests.getClassLoader().getResourceAsStream("the/resource/name")
, or, if a File
is required, new File(UnitTests.getClassLoader().getResource("the/resource/name").toURI())
.
On Java 8, you could try something like:
URI uri = UnitTests.class.getClassLoader().getResource("the/resource/name").toURI();
String string = new String(Files.readAllBytes(Paths.get(uri)), Charset.forName("utf-8"));