public static String slurp (final File file)throws IOException { StringBuilder result = new StringBuilder(); BufferedReader reader = new BufferedReader(new FileReader(file)); try { char[] buf = new char[1024]; int r = 0; while ((r = reader.read(buf)) != -1) { result.append(buf, 0, r); } } finally { reader.close(); } return result.toString();}
↧
Answer by Scott S. McCoy for How do I create a Java string from the contents of a file?
↧