The Sea The Sea - 1 year ago 164
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.


Answer Source

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

URL url = Resources.getResource("foo.txt");
String text = Resources.toString(url, Charsets.UTF_8);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download