应用FileInputStream类,编写应用程序,从磁盘上读取一个Java程序,并将源程序代码显示在屏幕上。(被读取的文件路径为:d:/myjava/Hello.java 内容自己决定);

package stage3;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;

public class Test6 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        File f = new File("d:/data/Hello.java");
        try(FileInputStream fin = new FileInputStream(f);
        BufferedInputStream bin = new BufferedInputStream(fin);
        PrintStream ps = new PrintStream(System.out); ){
            byte [] b = new byte[(int)f.length()];
            bin.read(b);
            ps.println(new String(b,"gbk"));
        }catch(IOException e) {
            e.printStackTrace();
        }
        
        
    }

}

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄