字节输入流InputStream

迷南。 2023-08-17 16:09 131阅读 0赞
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. public class FileInputStreamDemo {
  5. public static void main(String[] args) throws IOException {
  6. File file = new File("E:\\IO流\\java\\1.txt");
  7. FileInputStream f = new FileInputStream(file);
  8. int n = 0;
  9. while ((n = f.read()) != -1) {
  10. System.out.print((char) n);
  11. }
  12. f.close();
  13. }
  14. }

1392562-20190816194944521-912566256.png

1392562-20190816195014903-1918130622.png

2、缓冲流BufferedInputStream

  1. package pers.zaw.in;
  2. import java.io.BufferedInputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. public class BufferedInputStreamDemo {
  7. public static void main(String[] args) throws IOException {
  8. File file = new File("E:\\IO流\\java\\1.txt");
  9. FileInputStream f = new FileInputStream(file);
  10. BufferedInputStream in = new BufferedInputStream(f);
  11. int n = 0;
  12. while ((n = in.read()) != -1) {
  13. System.out.print((char) n);
  14. }
  15. in.close();
  16. }
  17. }

转载于:https://www.cnblogs.com/zhai1997/p/11366015.html

发表评论

表情:
评论列表 (有 0 条评论,131人围观)

还没有评论,来说两句吧...

相关阅读