Skip to content

Instantly share code, notes, and snippets.

@thiagofa
Created October 17, 2019 20:52
Show Gist options
  • Save thiagofa/8ea41a1d58aeb74ece0adfc17b9a47ef to your computer and use it in GitHub Desktop.
Save thiagofa/8ea41a1d58aeb74ece0adfc17b9a47ef to your computer and use it in GitHub Desktop.
Classe utilitária que retorna a string do conteúdo de um arquivo (recurso) do classpath
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.springframework.util.StreamUtils;
public class ResourceUtils {
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