java - 字节流读取文件

package stream;

import java.io.*;

public class InputStreamReaderString {

    public static void main(String[] args)  {

        File f = new File("src/stream","hello.txt");
        
        try(FileInputStream fis = new FileInputStream(f)){
            
            byte[] all = new byte[(int)f.length()];
            
            fis.read(all);
            
            String str = new String(all);
            
            System.out.println(str);
            
        }catch(IOException e) {
            e.printStackTrace();
        }
        
    }

}

 

posted @ 2020-10-21 21:29  武卡卡  阅读(173)  评论(0编辑  收藏  举报