The Sea The Sea - 10 months ago 62
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.



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

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