字节输入流

package it_03;

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

public class Demo10 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis =new FileInputStream("fos.txt");
        int read ;
        while((read=fis.read())!=-1){
            System.out.print((char)read);
        }
        fis.close();
    }
}

用字符数组读

package it_04;

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

public class Demo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis =new FileInputStream("fos.txt");
        byte[] b1 = new byte[1024];
        int len;
        while((len= fis.read(b1))!=-1){
            System.out.println(new String(b1,0,len));

        }
    }
}
posted @ 2025-04-22 16:17  lfqyj  阅读(3)  评论(0)    收藏  举报