Created
February 10, 2020 16:06
-
-
Save bcalmac/e78a73f887102f7592e463d08c2ce2a3 to your computer and use it in GitHub Desktop.
Load resource to string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.bcalmac.overtime.server.utils; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import java.net.URL; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
public class OvertimeTestUtils { | |
public static String loadResource(String resource) { | |
URL resourceURL = OvertimeTestUtils.class.getResource(resource); | |
if (resourceURL == null) { | |
throw new RuntimeException("Missing resource: " + resource); | |
} | |
try { | |
return Files.readString(Paths.get(resourceURL.toURI())); | |
} catch (IOException | URISyntaxException e) { | |
throw new RuntimeException("Failed to load resource: " + resource, e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires Java 11 for
Files.readString()
.