IO流自学笔记

什么是IO流?

I: 输入
O: 输出
流 : 线性有方向
作用:读写文件(不能操作文件夹)

分类:

字符流:只能读写纯文本文件

Writer():
        OutPutStreamWriter:
        FileWriter:
Reader():
        InPutStreamReader:
        FileReader:

字节流:可以读写任何类型的文件**.
OutPutStream()输出流:从 程序 向 外部 输出数据
InPutStream()输入流:从 程序 向 外部 读取数据
FileOutPutStream


FileOutPutStream


    //如果文件不存在会自动创建一个,
        //覆盖写.如果存在则覆盖创建一个新的空文件.
        FileOuPutStream out = new FileOuPutStream(String name);
        //追加写,如果存在,就保持原来的内容.
        FileOuPutStream out = 
                new FileOuPutStream(String name,true);
        //封装文件路径.
            FileOuPutStream out = 
                new FileOutPutStream(File file);
            FileOuPutStream out = 
                new FileOutPutStream(File file,true);
        //三种输出方法(写入到文件中)
        //write(int b);
        out.write(99);  
        //write(Byte[])
        byte[] byteArray = {97,98,99,100};
        out.write(byteArray);
        //write(Byte[] ,int off,int length)
        //输出换行 
        out.write("\r\n".getBytes());

FileInPutStream

构造方法

        //java中所有的输入流,构造时,必须存在,否则抛出异常.
        FileInPutStream in = new FileInPutStream(String path)
        FileInPutStream in = new FileInPutStream(File file)

读取方法:

        int read();
        //从文件中一次读一个字节,读取到文件末尾返回-1
        int b = in.read();
        //读取一个字节数组
        int read(Byte[]);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值