Test04.java 835 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.day19.io01;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.util.Arrays;
  5. /**
  6. * ClassName: Test01
  7. *
  8. * @Author 爱扣钉-陈晨
  9. * @Create 2024/1/17 9:44
  10. * @Version 1.0
  11. */
  12. public class Test04 {
  13. public static void main(String[] args) throws IOException {
  14. //循环读取文件
  15. FileInputStream fis = new FileInputStream("day19\\file\\b.txt");
  16. //数组
  17. byte[] bytes = new byte[2];
  18. int l1 = fis.read(bytes);
  19. System.out.println(l1);
  20. System.out.println(Arrays.toString(bytes));
  21. int l2 = fis.read(bytes);
  22. System.out.println(l2); //读取到一个
  23. System.out.println(Arrays.toString(bytes));
  24. new String(bytes,0,1);
  25. //释放资源
  26. fis.close();
  27. }
  28. }