// iostreams/BufferedInputFile.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // {ValidateByHand} import java.io.*; public class BufferedInputFile { public static String read(String filename) throws IOException { try( BufferedReader in = new BufferedReader( new FileReader(filename)) ) { String s; StringBuilder sb = new StringBuilder(); while((s = in.readLine())!= null) sb.append(s + "\n"); return sb.toString(); } } public static void main(String[] args) throws IOException { System.out.print(read("BufferedInputFile.java")); } }