The Sea The Sea - 3 months ago 21
Java Question

Utils read resource text file to String (Java)

Is there any Utils help reader a textfile in resource into a String. I suppose this is a popular requirement, but I couldn't found any Utils after Googling.

Thanks

Answer

Yes, Guava provides this in the Resources class. For example:

URL url = Resources.getResource("foo.txt");
String text = Resources.toString(url, Charsets.UTF_8);