Skip to content

Instantly share code, notes, and snippets.

@viniciusrplima
Created January 2, 2022 17:54
Show Gist options
  • Save viniciusrplima/8dba1f889c0bdafc236a56e195dc35bd to your computer and use it in GitHub Desktop.
Save viniciusrplima/8dba1f889c0bdafc236a56e195dc35bd to your computer and use it in GitHub Desktop.
Component to load resource content
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