Java学习Day23:基础篇13

IO流大集合

1.创建文件

2.IO流及其分类

1.字节流

3.输入流

4.输出流

public class CreatFile {
    public static void main(String[] args) {
        creat();
    }
    static void creat(){
        String path ="D:\\a\\qwqe.txt";
        FileOutputStream f =null;
        String str ="qweqweqweqwe";
        try {
            f=new FileOutputStream(path,true);
            f.write(str.getBytes(),0,4);
            System.out.println("1");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

5.输入加输出拷贝图片

public class fileCopy
{
    public static void main(String[] args) {
        String inputpass ="D:\\pic\\bg3.jpg";
        String outputpass ="D:\\pic\\a\\bg3.jpg";
        FileInputStream fileInputStream =null;
        FileOutputStream fileOutputStream =null;
        int readline;
        byte [] bytee =new byte[1024];
        try {
            fileInputStream=new FileInputStream(inputpass);
            fileOutputStream =new FileOutputStream(outputpass);
            while ((readline= fileInputStream.read(bytee))!=-1){
                fileOutputStream.write(bytee);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (fileInputStream!=null){
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (fileOutputStream!=null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
      

2.字符流

public class zifuliu {
    public static void main(String[] args) {
        String filepath ="D:\\a\\a.txt";
        FileReader fileReader=null;
        int raedline=0;
        char [] bytee =new char[1024];
        try {
            fileReader=new FileReader(filepath);
            while ((raedline= fileReader.read(bytee))!=-1){
                System.out.println(new String(bytee,0,raedline));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (fileReader!=null){
                try {
                    fileReader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

写完之后用close最好,falsh也可以;

3.节点流、处理流

节点流:

对特定的数据(文件、数组、管道、字符串)进行操作;

处理流(包装流):

包装节点流使之功能更加强大,其中的一个属性是节点流,可以是数组,数据源等 ,只要是节点流都可以放但是只能放一个;

区别与联系

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值