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

来源:互联网 发布:大数据与银行 编辑:程序博客网 时间:2024/05/29 19:44

打印出文件内信息

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();            }        }    }}
0 0
原创粉丝点击