java字节流读取文件


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

//读取数据
public class FileInputStream1 {
    public static void main(String[] args) throws IOException {
        FileInputStream stream = new FileInputStream("E:\\Workpace\\abc.txt");
        int b;
        while((b = stream.read()) != -1){
            System.out.print((char)b);
        }
        stream.close();
    }
}



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

public class FileInputStream3 {
    public static void main(String[] args) throws IOException {
        FileInputStream inputStream = new FileInputStream("E:\\Workpace\\abc.txt");
        byte[] bytes = new byte[1024];
        int len;
        while((len = inputStream.read(bytes)) != -1){
            System.out.println(new String(bytes,0,len));
        }
        inputStream.close();
    }
}


posted @ 2021-05-01 09:48  code-G  阅读(694)  评论(0编辑  收藏  举报