例子

读取文件

  1. import java.io.*;
  2. public class Main {
  3. public static void main(String[] args) throws Exception {
  4. String path = "./story.txt";
  5. BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path));
  6. byte[] buffer = new byte[2048];
  7. int readLen = 0;
  8. while ((readLen = bis.read(buffer)) != -1) {
  9. System.out.println(new String(buffer, 0, readLen));
  10. }
  11. bis.close();
  12. }
  13. }