I like akosicki's answer with the Stupid Scanner Trick. It's the simplest I see without external dependencies that works in Java 8 (and in fact all the way back to Java 5). Here's an even simpler answer if you can use Java 9 or higher (since InputStream.readAllBytes()
was added at Java 9):
String text = new String(AppropriateClass.class.getResourceAsStream("foo.txt").readAllBytes());