IO的字节读取

package lirixing.b;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class Inp {
    public static void main(String[] args) throws IOException {
        test2();

    }
    /**
     * 文件输入流的创建方式以及字节缓冲流
     */
    private static void test2() throws IOException {
        FileInputStream fis=new FileInputStream("d:/hello.txt");  // 2
        BufferedInputStream bis=new BufferedInputStream(fis);
        int b=0;
        StringBuilder sb=new StringBuilder();
        while ((b=bis.read())!=-1) {
            sb.append((char)b);

        }
        System.out.println(sb.toString());
        bis.close();
    }
}
posted @ 2022-08-11 18:50  码海兴辰  阅读(15)  评论(0)    收藏  举报