OnJava8-Examples/io/BufferedInputFile.java

26 lines
670 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// io/BufferedInputFile.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
import java.io.*;
public class BufferedInputFile {
// Throw exceptions to console:
public static String
read(String filename) throws IOException {
StringBuilder sb;
// Reading input by lines:
try(BufferedReader in = new BufferedReader(
new FileReader(filename))) {
String s;
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"));
}
2015-09-07 11:44:36 -06:00
}
/* Output: (Execute to see) */