package com.sf._03_字节输入流;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Test2 {
    public static void main(String[] args) throws IOException {
        /**
         * 最终需要通过while 循环进行优化读取内容
         *
         */
        FileInputStream fileInputStream = new FileInputStream(new File("D:\\a.txt"));
        // 读取长度默认值是-1
        int len = -1;

        // 创建byte数组, 一次性用于读取多个字节
        byte[] buffer = new byte[4];

        while ((len = fileInputStream.read(buffer))!=-1){
            // 打印读取内容
            System.out.println("读取内容为:"+ new String(buffer,0,len));

        }

        // 把资源关闭掉
        fileInputStream.close();


    }
}
