BufferedInputFile

BufferedInputFile

在java编程思想P542页中引用了一个BufferedInputFile类,这个类老夫没有在Java 的API中找到,就去http://www.mindviewinc.com/TIJ4/CodeInstructions.html这下载下来,找到该类,代码如下:

//: io/BufferedInputFile.java
import java.io.*;

public class BufferedInputFile {
  // Throw exceptions to console:
  public static String
  read(String filename) throws IOException {
    // Reading input by lines:
    BufferedReader in = new BufferedReader(
      new FileReader(filename));
    String s;
    StringBuilder sb = new StringBuilder();
    while((s = in.readLine())!= null)
      sb.append(s + "\n");
    in.close();
    return sb.toString();
  }
  public static void main(String[] args)
  throws IOException {
    System.out.print(read("BufferedInputFile.java"));
  }
} /* (Execute to see output) *///:~

希望对大家有帮助!

你可能感兴趣的:(Java)