Practical use of Java-IO streams (search and classification of emoticons)

I have been learning IO flow for a long time, but I have never actually used it. Today, I felt that the efficiency was too low when saving the emoji in the group chat, so I wrote a simple console program to help me save it.
Insert picture description here

This is the address where qq stores the pictures. It used to be a bunch of pictures without extracting it. Now it’s changed to this multi-folder format. It would be too slow
to open them one by one manually .

public static void main(String[] args) {
    
    
        //设置文件路径,把22735改成自己计算机名即可
        File file = new File("C:\\Users\\计算机名\\Documents\\Tencent Files\\想要获取的QQ号\\Image\\Group2");
        fun(file);
    }

    public static void fun(File dir) {
    
    
        //调用listFiles方法对目录进行遍历
        File[] filearr = dir.listFiles();
        for (File file : filearr)
        {
    
    
            if (file.isDirectory())
            {
    
    
                fun(file);//判断如果是文件夹就继续调用遍历目录下内容的方法,形成递归
            }else {
    
    
                if(file.getName().indexOf(".")>0){
    
    
                    copy(file,new File("C:Users\\计算机名\\Documents\\Tencent Files\\想要获取的QQ号\\Image\\存放地址\\"+file.getName()));
                }
            }
        }
    }
    public static void copy(File file, File destFile)  {
    
    
        FileInputStream ins = null;
        FileOutputStream ios = null;
        try{
    
    
            ins = new FileInputStream(file);
            ios = new FileOutputStream(destFile);
            byte[] buf = new byte[1024];
            int size = 0;
            while((size = ins.read(buf))!=-1){
    
    
                ios.write(buf,0,size);
            }
        }
        catch (IOException e){
    
    
            e.printStackTrace();
        }
    }

In fact, the principle is very simple. It is to search all the way down from the image to form a recursive search. When the suffix is ​​called the picture format, copy it to the address where you want to store
Insert picture description here
it, and save it one by one when you see what you like. Write another ai to automatically recognize the second element sister and save it automatically...

Guess you like

Origin blog.csdn.net/qq_36008278/article/details/114881464