java学习笔记之——文件输入流

时间:2021-09-21 21:55:16

打印出文件内信息

import java.io.FileInputStream;



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

public class FileInputStreamDemo {

    public static void main(String[] args) {


        FileInputStream fis = null;
        try {

            fis = new FileInputStream(
                    “文件路径”);

            byte[] bbuf = new byte[1024];

            int hasRead = 0;

            while ((hasRead = fis.read(bbuf)) > 0) {

                System.out.print(new String(bbuf, 0, hasRead));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {

                fis.close();
            } catch (IOException e) {

                e.printStackTrace();
            }
        }
    }
}