io流详解

IO流

什么是IO流

在这里插入图片描述

什么是数据源

在这里插入图片描述

原设备:输入流

目标设备:输出流

什么是流

在这里插入图片描述

在这里插入图片描述

四大IO抽象类

字节流

inputStream
在这里插入图片描述

outputStream

在这里插入图片描述

字符流

reader

在这里插入图片描述

在这里插入图片描述

流的细分

按流的方向分

在这里插入图片描述

按流的数据单元分类

在这里插入图片描述

按处理对象不同分类

在这里插入图片描述
在这里插入图片描述

IO流体系

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

入门案例

public class Demo01 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
            //创建字节流对象
            fis = new FileInputStream("e:/a.txt");
            int s1 = fis.read();//打印输入字符a对应的ascii码值97
            int s2 = fis.read();//打印输入字符b对应的ascii码值98
            int s3 = fis.read();//打印输入字符c对应的ascii码值99
            int s4 = fis.read();//由于文件内容读取完毕,返回-1
            System.out.println(s1);
            System.out.println(s2);
            System.out.println(s3);
            System.out.println(s4);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

        }

    }
}
        /*结果
        97
        98
        99
        -1
        */

改造入门案例

public class Demo02 {
    public static void main(String[] args) {
        FileInputStream fis =null;
        try {
            fis = new FileInputStream("e:/a.txt");
            StringBuilder sb = new StringBuilder();
            //用循环代替了多次调用read方法
            int temp = 0;
            while ((temp=fis.read())!=-1){
                System.out.println(temp);
                sb.append((char)temp);
            }
            System.out.println(sb);
        }catch (Exception e){
            e.printStackTrace();
            }finally {
            if(fis!=null){
                try {
                    fis.close();

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
/*
结果
97
98
99
abc
 */

file类的使用

针对文件操作的方法

在这里插入图片描述
在这里插入图片描述

实例
public class Demo03 {
    public static void main(String[] args) throws Exception{
        File file = new File("e:/aa.txt");
        //System.out.println(file.createNewFile());//创建
        //System.out.println(file.delete());//删除文件
        System.out.println(file.exists());//检测是否存在
        System.out.println(file.getName());//获取文件名
        System.out.println(file.isFile());//是否是文件
        System.out.println(file.isHidden());//是否隐藏
    }
}
/*
结果
true
aa.txt
true
false
 */

针对目录操作的方法

在这里插入图片描述

实例
public class Demo04 {
    public static void main(String[] args) {
        File file = new File("e:/b/c");
        //System.out.println(file.mkdir());//创建单级目录
        //System.out.println(file.mkdirs());//创建多级目录
        //System.out.println(file.exists());//查询目录是否存在
        //System.out.println(file.getParentFile().getName());//输出父目录名
        //System.out.println(file.getParent());//输出父目录绝对路劲
        File file1 = new File("e:/");
        String[] arr = file1.list();//输出e盘下所有的文件名
        for (String temp:arr) {
            System.out.println(temp);
        }
        System.out.println("================================");
        File file2 = new File("e:/");
        File[]arr2 = file2.listFiles();//输出e盘下所有的文件的绝对路径
        for (File temp:arr2) {
            System.out.println(temp);
        }

    }
}
/*
结果
$RECYCLE.BIN
a.txt
aa.txt
b
cajv
Dingding
HTML-5
ideaIU-2020.1.3.exe
ideal
idle project
javaSE
Mysql
Navicat for MySQL
notepad++安装包
pr
python
python实例
QQ
System Volume Information
typora-setup
typora-setup-x64.exe
vscode
wechat
破解码.txt
考研直播课
腾讯会议
================================
e:\$RECYCLE.BIN
e:\a.txt
e:\aa.txt
e:\b
e:\cajv
e:\Dingding
e:\HTML-5
e:\ideaIU-2020.1.3.exe
e:\ideal
e:\idle project
e:\javaSE
e:\Mysql
e:\Navicat for MySQL
e:\notepad++安装包
e:\pr
e:\python
e:\python实例
e:\QQ
e:\System Volume Information
e:\typora-setup
e:\typora-setup-x64.exe
e:\vscode
e:\wechat
e:\破解码.txt
e:\考研直播课
e:\腾讯会议
 */

常用流对象

文件字节流

在这里插入图片描述

文件字节输入流
public class Demo06 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
           fis =  new FileInputStream("e:\\b\\c\\123.png");
           int temp = 0;
           while ((temp = fis.read())!=-1){
               System.out.println(temp);
           }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (fis!=null)
                fis.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
输出结果都是小于255的数字
文件字节输出流
public class Demo07 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis =  new FileInputStream("e:\\b\\c\\123.png");
            fos =  new FileOutputStream("e:\\b\\c\\234.png");
            int temp = 0;
            while ((temp = fis.read())!=-1){
                fos.write(temp);
            }
            //将数据从内存中写入到磁盘中
            fos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (fos!=null){
                    fos.close();
                }

                if (fis!=null){
                    fis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
通过缓冲区提高读写效率
方法一

在这里插入图片描述

public class Demo08 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis =  new FileInputStream("e:\\b\\c\\123.png");
            fos =  new FileOutputStream("e:\\b\\c\\234.png");
            //创建一个缓冲区(新建数组存放单个二进制数据)提高读写效率
            byte[] arry = new byte[1024];
            int temp = 0;
            while ((temp = fis.read(arry))!=-1){
                fos.write(arry,0,temp);
            }
            //将数据从内存中写入到磁盘中
            fos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (fos!=null){
                    fos.close();
                }

                if (fis!=null){
                    fis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
方法二

在这里插入图片描述

    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis =  new FileInputStream("e:\\b\\c\\123.png");
            fos =  new FileOutputStream("e:\\b\\c\\345.png");
            //创建一个缓冲区提高读写效率
            byte[] arry = new byte[fis.available()];
            fis.read(arry);
            fos.write(arry);
            //将数据从内存中写入到磁盘中
            fos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (fos!=null){
                    fos.close();
                }

                if (fis!=null){
                    fis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

方法二适合一些比较小的文件,如果文件过大还是建议采用方法一

通过字节缓冲区提高读写效率

在这里插入图片描述

public static void main(String[] args) {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try {
    //bis方法把fis方法封装起来
        fis = new FileInputStream("e:\\b\\c\\123.png");
        bis = new BufferedInputStream(fis);
    //bos方法把bis方法封装起来
        fos = new FileOutputStream("e:\\b\\c\\789.png");
        bos = new BufferedOutputStream(fos);
        //缓冲流byte数组长度默认是8192
        int temp = 0;
        //bis方法通过循环读取数据
        while ((temp = bis.read())!=-1){
        //bos方法将数据写入指定文件
            bos.write(temp);
        }
        bos.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if(bis !=null){
                bis.close();
            }
            if(fis !=null){
                fis.close();
            }
            if (bos !=null){
                bos.close();
            }
            if(fos !=null){
                fos.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
定义文件拷贝工具类
public static void main(String[] args) {
//调用复制文件的方法
    copy("e:\\b\\c\\123.png","e:\\b\\c\\1.png");

}
//定义一个复制文件的方法
public static void copy(String src,String des){
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    FileOutputStream fos  = null;
    BufferedOutputStream bos = null;
    try {
        bis = new BufferedInputStream(new FileInputStream(src));
        bos = new BufferedOutputStream(new FileOutputStream(des));
        int temp = 0;
        while ((temp = bis.read()) !=-1){
            bos.write(temp);
        }
        bos.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if(bis != null){
                bis.close();
            }
            if(fis != null){
                fis.close();
            }
            if(bos != null){
                bos.close();
            }
            if(fos != null){
                fos.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}

文件字符流

在这里插入图片描述

文件字符输入流
public static void main(String[] args) {
    FileReader frd = null;
    try {
        frd = new FileReader("E:/b/c/a.txt");
        int temp = 0;
        while ((temp = frd.read()) !=-1){
            System.out.println((char) temp);
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (frd !=null){
                frd.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
文件字符输出流
public class Demo13 {
    public static void main(String[] args) {
        FileWriter fw = null;
        FileWriter fw2 = null;
        try {
        	//如果文件存在,字符将会被输入,如果文件不存在,先创建文件后输入字符
            fw = new FileWriter("E:/b/c/aaa.txt");
            fw.write("杨鑫\r\n");
            fw.flush();
            //true 决定第二次输入的值是否被覆盖,如果没有true,默认为false,第二次输入的东西将会被覆盖
            fw2 = new FileWriter("E:/b/c/aaa.txt",true);
            fw2.write("何佳琪");
            fw2.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(fw != null){
                    fw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
使用字符流实现文本文件的拷贝处理
public static void main(String[] args) {
    FileWriter fw = null;
    FileReader fr = null;
    try {
        fr = new FileReader("E:\\b\\c\\aaa.txt");
        fw = new FileWriter("E:\\b\\c\\b.txt");
        int temp = 0;
        char [] arry = new char[1024];
        while ((temp  =fr.read(arry)) !=-1){
            fw.write(arry);
        }
        fw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try{

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

字符缓冲流

在这里插入图片描述

字符输入缓冲流

在这里插入图片描述

public static void main(String[] args) {
    FileReader fr = null;
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("E:\\b\\c\\b.txt"));
        String temp = "";
        while ((temp = br.readLine()) != null){
            System.out.println(temp);
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (fr != null){
                fr.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
字符输出缓冲流

在这里插入图片描述

public static void main(String[] args) {
    FileWriter fw = null;
    BufferedWriter bw = null;
    try {
        bw = new BufferedWriter(new FileWriter("E:\\b\\c\\b1.txt"));
        bw.write("你好杨鑫");
        bw.write("你好何佳琪");
        bw.newLine();//换行处理
        bw.write("我们永远在一起吧");
        bw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (bw != null){
                bw.close();
            }
            if (fw != null){
                fw.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
通过字符缓冲流实现文本的拷贝
public static void main(String[] args) {
    copy("E:\\b\\c\\b1.txt","E:\\b\\c\\b2.txt");

}
//构造一个字符缓冲流复制文本的方法(工具)
public static void copy(String src,String des){
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        br = new BufferedReader(new FileReader(src));
        bw = new BufferedWriter(new FileWriter(des));
        String temp = "";
        while ((temp = br.readLine()) != null){
            bw.write(temp);
            bw.newLine();
        }
        bw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (bw != null){
                bw.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
通过字符缓冲流为文件中的内容添加行号
public static void main(String[] args) {
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        br = new BufferedReader(new FileReader("E:\\b\\c\\b1.txt"));
        bw = new BufferedWriter(new FileWriter("E:\\b\\c\\b3.txt"));
        String temp = "";
        int i = 1;
        while ((temp = br.readLine()) != null){
            bw.write(i+"."+temp);
            bw.newLine();
            i++;
        }
        bw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (bw != null){
                bw.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

转换流

在这里插入图片描述

通过转换流实现键盘输入屏幕输出
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
            while (true){
                bw.write("请输入:");
                bw.flush();
                String input = br.readLine();
                if ("exit".equals(input)){
                    break;
                }
                bw.write("你输入的是:"+input);
                bw.newLine();
                bw.flush();


            }


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (br != null){
                    br.close();
                }
                if (bw != null){
                    bw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
/*
结果:
请输入:123
你输入的是:123
请输入:456
你输入的是:456
请输入:何大炮
你输入的是:何大炮
请输入:exit

 */
通过字节流读取文本文件并添加行号
public static void main(String[] args) {
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        //层层嵌套
        br = new BufferedReader(new InputStreamReader(new FileInputStream("E:\\b\\c\\b1.txt")));
        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("E:\\b\\c\\b5.txt")));
        String temp = "";
        int i = 1;
        while ((temp = br.readLine()) != null){
            bw.write(i+"."+temp);
            bw.newLine();
            i++;
        }
        bw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (bw != null){
                bw.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

字符输出流

在这里插入图片描述

public static void main(String[] args) {
    BufferedReader br = null;
    PrintWriter pw = null;
    try {
        //层层嵌套
        br = new BufferedReader(new InputStreamReader(new FileInputStream("E:\\b\\c\\b1.txt")));
        pw = new PrintWriter("E:\\b\\c\\b11.txt");
        String temp = "";
        int i = 1;
        while ((temp = br.readLine()) != null){
            pw.println(i+"."+temp);
            i++;
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (pw != null){
                pw.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

字节数组流

在这里插入图片描述

字节数组输入流

在这里插入图片描述

public static void main(String[] args) {
    byte[] arry = "abcdefgh".getBytes();
    ByteArrayInputStream bis = null;
    StringBuilder sb = new StringBuilder();
    try {
        //该构造方法的参数是一个字节数组,这个字节数组就是数据源
        bis = new ByteArrayInputStream(arry);
        int temp = 0;
        while ((temp = bis.read()) != -1){
            sb.append((char) temp);
        }
        System.out.println(sb.toString());
    }finally {
        try {
            if (bis != null){
                bis.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
字节数组输出流
public static void main(String[] args) {
    ByteArrayOutputStream bos = null;
    try {
        StringBuilder sb = new StringBuilder();
        bos = new ByteArrayOutputStream();
        bos.write('a');
        bos.write('b');
        bos.write('c');
        byte[] arry = bos.toByteArray();
        for (int i = 0; i <arry.length ; i++) {
            sb.append((char) arry[i]);
        }
        System.out.println(sb.toString());
    }finally {
        try {
            if (bos != null){
                bos.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

数据流

在这里插入图片描述

数据输出流
public static void main(String[] args) {
    DataOutputStream dos = null;
    try {
        dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("E:\\b\\c\\b12.txt")));
        dos.writeInt(10);
        dos.writeBoolean(true);
        dos.writeUTF("我是一头大蠢驴");
        dos.writeChar('a');
        dos.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (dos != null){
                dos.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
数据输入流
    public static void main(String[] args) {
        DataInputStream dis = null;
        try {
            dis = new DataInputStream(new BufferedInputStream(new FileInputStream("E:\\b\\c\\b12.txt")));
			//读取的顺序必须按照写入的顺序读取,不能打乱顺序否则会出现异常
            System.out.println("int:"+dis.readInt());
            System.out.println("boolean:"+dis.readBoolean());
            System.out.println("char:"+dis.readChar());
            System.out.println("String:"+dis.readUTF());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (dis != null){
                    dis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
/* 结果
        int:10
        boolean:true
        char:a
        String:我是一头大蠢驴
        */

对象流

在这里插入图片描述

对象的序列化和反序列化

在这里插入图片描述
在这里插入图片描述

序列化涉及的类和接口

在这里插入图片描述

操作基本数据类型

在这里插入图片描述

写出基本数据类型数据
public static void main(String[] args) {
    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("E:\\b\\c\\b13.txt")));
        oos.writeDouble(Math.random());
        oos.writeInt(10);
        oos.writeBoolean(false);
        oos.writeChar('f');
        oos.writeUTF("大炮宝宝");
        oos.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (oos != null){
                oos.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
读取基本数据类型数据
 public static void main(String[] args) {
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream("E:\\b\\c\\b13.txt")));
            //数据读取的顺序与写入数据的顺序要完全一致,否则会出现异常
            System.out.println("double:"+ois.readDouble());
            System.out.println("int:"+ois.readInt());
            System.out.println("boolean:"+ois.readBoolean());
            System.out.println("char:"+ois.readChar());
            System.out.println("String:"+ois.readUTF());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (ois != null){
                    ois.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
/*
结果:
double:0.6500226022788321
int:10
boolean:false
char:f
String:大炮宝宝
 */
操作对象
将对象序列化到文件

在这里插入图片描述

创建对象
public class Users implements Serializable {
    private int id = 10;
    private int age = 18;
    private String name = "paopao";
    //有参构造
    public Users(int id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }
    //无参构造
    public Users() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
序列化对象
public static void main(String[] args) {
    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(new FileOutputStream("E:\\b\\c\\b14.txt"));
        Users users = new Users(20,22,"paopao");
        oos.writeObject(users);
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (oos != null){
                oos.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
将对象反序列化到内存中
public static void main(String[] args) {
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(new FileInputStream("E:\\b\\c\\b14.txt"));
        Users users = (Users)ois.readObject();
        System.out.println(users.getAge()+"\t"+users.getId()+"\t"+users.getName());
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (ois != null){
                ois.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

随机访问流

在这里插入图片描述

在这里插入图片描述

public static void main(String[] args) {
    RandomAccessFile raf = null;
    try {
        raf = new RandomAccessFile("E:\\b\\c\\b15.txt","rw");
        int[] array = new int[]{10,20,30,40,50,60,70,80,90,100};
        for (int i = 0; i <array.length ; i++) {
            raf.writeInt(array[i]);
        }
        raf.seek(4);//指针指向第四个字节取数
        System.out.println(raf.readInt());
        //隔一个数,读一个数
        for (int i = 0; i <10 ; i+=2) {
            raf.seek(i*4);
            System.out.print(raf.readInt()+"\t");
        }
        System.out.println();
        //在第8的位置用一个新的数字替换原来的数字
        raf.seek(8);
        raf.writeInt(40);
        for (int i = 0; i <10 ; i+=2) {
            raf.seek(i*4);
            System.out.print(raf.readInt()+"\t");
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (raf != null){
                raf.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

File类在IO中的作用

在这里插入图片描述

public static void main(String[] args) {
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        br = new BufferedReader(new FileReader(new File("E:\\b\\c\\aaa.txt")));
        bw = new BufferedWriter(new FileWriter(new File("E:\\b\\c\\b16.txt")));
        String temp = "";
        int i = 1;
        while ((temp = br.readLine()) != null){
            bw.write(i+"."+temp);
            bw.newLine();
            i++;
        }
        bw.flush();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (br != null){
                br.close();
            }
            if (bw != null){
                bw.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

Apache IO包

在这里插入图片描述

FileUtils的使用

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

    public static void main(String[] args) throws IOException {
        String s = FileUtils.readFileToString(new File("e:\\b\\c\\aaa.txt"),"utf-8");
        System.out.println(s);
    }
public static void main(String[] args) throws IOException {
    FileUtils.copyDirectory(new File("E:\\b\\c"), new File("d:b\\a"), new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            if(pathname.isDirectory()||pathname.getName().endsWith("png")){
                return true;
            }
            return false;
        }
    });
}
public static void toString1() throws IOException {
    String s= IOUtils.toString(new FileInputStream("e:\\b\\c\\aaa.txt"), "utf-8");

    System.out.println(s);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值