使用文件字节输入流FileInputStream读取文件

2020-10-23 10:30:27 浏览数 (1)

1.在e盘下创建aaa.txt文件

2.代码

代码语言:javascript复制
package d01_TestInput;/*
 * zt
 * 2020/8/7
 * 10:33
 *
 */


import java.io.FileInputStream;

public class Test1 {
    public static void main(String[] args) throws Exception {
        FileInputStream fis = new FileInputStream("e:\aaa.txt");

        byte[] buf = new byte[1024];
        int len=0;
        /*len = fis.read(buf);
        System.out.println(new String(buf,0,len));
        len = fis.read(buf);
        System.out.println(new String(buf,0,len));*/
        while((len = fis.read(buf))!=-1){
            System.out.println(new String(buf,0,len));
        }
        fis.close();

    }
}

3.运行结果

代码语言:javascript复制
大大师傅?呱?i  love you 
txt

0 人点赞