java148-三个参数的输入流

    //3个参数读取二进制文件
    import java.io.*;
     
    public class FileManage {
        public static void readBitFile(String filename){
            //1建立目标要读取的文件对象
            File file=new File( filename );
            //2基于目标对象建立输入流
            InputStream in=null;
            if(file.exists()){//如果文件存在,创建文件输入流
                System.out.println( "文件的长度"+file.length() );
                try {
                    in = new FileInputStream( file );//使用子类inputstream输入流
                    int count = 0;//读取的字节数
                    byte []bys=new byte[124];//临时存储读取的二进制数据
                    while((count=in.read(bys,0,bys.length))!=-1) {
                        String s=new String(bys,0,count);
                        System.out.print( s);
                    }
                }catch (FileNotFoundException e){
                    e.printStackTrace();
                }catch (IOException e){
                    e.printStackTrace();
                }finally {
                    try {
                        in.close();
                        System.out.println( "关闭成功" );
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }
            //读取文件内容
     
            //关闭输入流
        }
    }

测试类

    public class test93 {
        public static void main(String[] args){
            FileManage.readBitFile( "e:/1.txt" );
        }
    }

运行结果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值