利用FileInputStream类在控制台打印文件内容

import java.io.*;

public class TestFileInputStream{
    
    public static void main(String[] args){
        
        FileInputStream in = null;
        
        try{
            in = new FileInputStream("D:/Java/TestFileInputStream/TestFileInputStream.java");
        } catch(FileNotFoundException e){
            e.printStackTrace();
        }
        try{
            int b = 0;
            while((b = in.read()) != -1){
                System.out.print((char)b);
            }
            in.close();
        } catch(IOException e){
            e.printStackTrace();
        }
    }
        
}

猜你喜欢

转载自www.cnblogs.com/yxfyg/p/12394412.html