Created
October 17, 2019 20:52
-
-
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
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
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