Created
January 2, 2022 17:54
-
-
Save viniciusrplima/8dba1f889c0bdafc236a56e195dc35bd to your computer and use it in GitHub Desktop.
Component to load resource content
This file contains hidden or 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
import org.springframework.util.ResourceUtils; | |
import org.springframework.util.StreamUtils; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.nio.charset.Charset; | |
public class ResourceUtil { | |
public static String getContentFromResource(String resourceName) { | |
try { | |
InputStream stream = ResourceUtils.class.getResourceAsStream(resourceName); | |
return StreamUtils.copyToString(stream, Charset.forName("UTF-8")); | |
} | |
catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment