java字节流读取文件

2021/5/1 12:56:55

本文主要是介绍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();
    }
}




这篇关于java字节流读取文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程