2015-04-20 15:36:01 -07:00
|
|
|
|
//: io/BufferedInputFile.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
|
|
public class BufferedInputFile {
|
|
|
|
|
// Throw exceptions to console:
|
|
|
|
|
public static String
|
|
|
|
|
read(String filename) throws IOException {
|
2015-05-05 14:05:39 -07:00
|
|
|
|
StringBuilder sb;
|
|
|
|
|
try ( // Reading input by lines:
|
|
|
|
|
BufferedReader in = new BufferedReader(
|
|
|
|
|
new FileReader(filename))) {
|
|
|
|
|
String s;
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
while((s = in.readLine())!= null)
|
|
|
|
|
sb.append(s + "\n");
|
|
|
|
|
}
|
2015-04-20 15:36:01 -07:00
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
public static void main(String[] args)
|
|
|
|
|
throws IOException {
|
|
|
|
|
System.out.print(read("BufferedInputFile.java"));
|
|
|
|
|
}
|
|
|
|
|
} /* (Execute to see output) *///:~
|