A flexible solution using IOUtils from Apache commons-io in combination with StringWriter:
Reader input = new FileReader();StringWriter output = new StringWriter();try { IOUtils.copy(input, output);} finally { input.close();}String fileContents = output.toString();
It works with any reader or input stream (not just with files), for example when reading from a URL.