Share a small program to clean up garbage in memory cards and USB flash drives

Y2J
Release: 2017-05-06 11:04:19
Original
2969 people have browsed it

There is a scenario where the phone’s memory card space is used up, but I don’t know which file is taking up too much. It’s too troublesome to find each folder, so I developed a small program to store all the files on the phone (including Files under all subfolders under the path) are sorted so that you can find out which file takes up too much memory.

The usage example is as follows, use JAVA to run Sort

1, and enter the path of the files you want to sort. For example, the example is to process the files under H:\ and the files under all its subfolders. Sort

2. Enter the latest size that needs to be sorted and displayed. For example, the example is to sort files above 10M in size

3. Sort from large to small and press

File path\file name-------Size KB--------Creation date is displayed (yyyyMMdd)

format is displayed.

This way you can delete files that are too large and clear up space

D:\hjbsSorft\work\20140207\SortSize\bin>java com.he.jinbin.Sort
Enter the address of the file to be sorted: H:\
Enter the size of the file to be sorted (unit M): 10
Running, please wait...
Sort files from large to small as:
H:\.android_secure\com.sg.android.fish-1.asec-------36224000 KB--------20130525
H:\BaiduMap\vmp\h\quanguogailue.dat -------27616013 KB--------20130512
H:\Download\RedGame_Android_2017-2013-11-06_18-54-27-CI-20.apk------- 26563096 KB--------20131111
H:\ugame\ugameSDK\downloads\6F9757F4442DD99FC89FA387C80405D2.apk-------26305964KB--------20131025
H:\Download \com.tencent.mobileqq_60.apk-------25417880 KB--------20130714
H:\Android\data\com.android.gallery3d\cache\imgcache.0--- ----22070789 KB--------20140210
H:\book\2014\ Different World Lingwu Tianxia\ Different World Lingwu Tianxia.txt-------20279247 KB----- ---20131114
H:\book\In-depth java virtual machine.pdf-------19936351 KB--------20130303
H:\book\2014\Guantu\Guantu. txt-------19668417 KB--------20130907
H:\book\Taoist Priests in Jin Yong's World.txt-------19004109 KB------- -20130102
H:\wandoujia\patch\快播_1390061188726.patch-------18649129 KB--------20140119
H:\BaiduMap\vmp\h\guangzhou_257. dat-------16645639 KB--------20140120
H:\book\War Emperor.txt-------15588332 KB--------20121215
H:\Download\com.tencent.mobileqq_52.apk-------15128435 KB--------20130521
H:\book\2014\Super Farmer\Super Farmer.txt- ------13913630 KB--------20130807
H:\book\2014\Tang Yin in Another World\Tang Yin in Another World.txt-------13328290 KB--- -----20130726
H:\book\2014\Doomsday Cockroach\Doomsday Cockroach.txt-------13177834 KB--------20131129
H:\book\2014 \Yi Jin Jing\Yi Jin Jing.txt-------12995888 KB--------20130715
H:\book\2014\The Red Alert of the Anti-Japanese War\The Red Alert of the Anti-Japanese War.txt- ------12828979 KB--------20130928
H:\book\new\道.txt-------12445787 KB--------20130326
H:\book\2014\1895 Gold Rush Country\1895 Gold Rush Country.txt-------12391071 KB--------20140104
H:\book\2014\Quan Chen\Quan Chen.txt -------11949796 KB--------20130726
H:\install\360weishi_167.apk-------11342128 KB--------20131009
H:\book\2013.9.19\Baiduditu.txt-------10776149 KB--------20130103
H:\install\baiduditu.apk------- 10685159 KB--------20130511
H:\DBOP\Resources\cfg\db.cfg-------10647552 KB--------20130520

The disadvantage of Windows is that it cannot display the size of the folder.

Only two categories,

package com.he.jinbin;import java.util.Date;/**
 * 用于排序逻辑实体类
 * 
 * @author 何锦彬    QQ 277803242
 * */public class FileItem implements Comparable {    private String fileName;    private long size;    private Date creatTime;    public FileItem(String fileName, long size, Date creaDate) {        // TODO Auto-generated constructor stub
        this.fileName = fileName;        this.size = size;        this.creatTime = creaDate;
    }    public String getFileName() {        return fileName;
    }    public void setFileName(String fileName) {        this.fileName = fileName;
    }    public long getSize() {        return size;
    }    public void setSize(long size) {        this.size = size;
    }    public Date getCreatTime() {        return creatTime;
    }    public void setCreatTime(Date creatTime) {        this.creatTime = creatTime;
    }

    @Override    public int compareTo(Object o) {        if (this.size > ((FileItem) o).getSize())            return 1;        return -1;
    }

}
Copy after login
package com.he.jinbin;import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Collections;import java.util.Date;import java.util.List;/**
 * 用于排序逻辑主类
 * 
 * @author 何锦彬    QQ 277803242
 * */public class Sort {    public static List<FileItem> fileItems = new ArrayList<FileItem>();    public static FileItem maxFileItem;    public final static long M_1 = 1024 * 1024;    public static long temp = M_1; // 默认大于1M的文件

    public static void addFileItem(File file) {
        File[] fileList = file.listFiles();        for (int i = 0; i < fileList.length; i++) {
            file = fileList[i];            if (file.isDirectory()) {
                addFileItem(file);
            } else {                if (file.length() > temp) {
                    fileItems.add(new FileItem(file.getPath(), file.length(),                            new Date(file.lastModified())));
                }

            }
        }

    }    public static void main(String[] args) throws IOException {
        String filePath = null;
        System.out.print("输入需要排序文件地址:");
        BufferedReader inRd = new BufferedReader(new InputStreamReader(
                System.in));
        filePath = inRd.readLine();
        System.out.print("输入需要排序文件大小(单位M):");
        inRd = new BufferedReader(new InputStreamReader(System.in));
        temp = Long.parseLong(inRd.readLine())*M_1;
        inRd.close();
        System.out.println("运行中,请稍等...");
        File file = new File(filePath);
        addFileItem(file);
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        Collections.sort(fileItems);
        System.out.println("从大到小文件排序为:");        for (int i = fileItems.size() - 1; i >= 0; i--) {
            FileItem item = fileItems.get(i);
            System.out.println(item.getFileName() + "-------" + item.getSize()                    + " KB" + "--------" + fmt.format(item.getCreatTime()));
        }

    }
}
Copy after login

Although simple, my personal opinion is that programs are just tools. A good program is a program that brings convenience to life. It is not for showing off technology, just for practicality

【Related recommendations】

1. WeChat mini program source code download

2. WeChat mini program demo: imitation mall

The above is the detailed content of Share a small program to clean up garbage in memory cards and USB flash drives. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!