Share a small program to clear memory cards and spam in a USB flash drive.

Source: Internet
Author: User
There is a scenario where the memory card space of the mobile phone is used up, but you do not know which file occupies too much space. it is too troublesome to find folders one by one, so I developed a small program to sort all the files on the mobile phone (including the files in all levels of subfolders under the path), so that you can find out which file occupies too much memory. There is a scenario where the memory card space of the mobile phone is used up, but you do not know which file occupies too much space. it is too troublesome to find folders one by one, so I developed a small program to sort all the files on the mobile phone (including the files in all levels of subfolders under the path), so that you can find out which file occupies too much memory.

An example is as follows: run Sort in JAVA

1. enter the file path you want to sort. for example, sort the files under H: \ and the files in all its subfolders.

2. enter the latest size to be sorted and displayed. for example, sort files larger than 10 MB.

3. Sort

File path \ file name ------- size KB -------- creation date (yyyyMMdd)

Format ,.

In this way, you can delete a large file and clear the space.

D: \ hjbsSorft \ work \ 20140207 \ SortSize \ bin> java com. he. jinbin. Sort
Enter the address of the file to be sorted: H :\
Input file size to be sorted (unit: M): 10
Running. please wait...
Sort large to small files as follows:
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 worlds of arms txt ------- 20279247 KB--------20131114
H: \ book \ deep Java virtual machine certificate ------- 19936351 KB--------20130303
H: \ book \ 2014 \ .txt ------- 19668417 KB--------20130907
H: \ book \ Jin Yong World's Taoist .txt ------- 19004109 KB--------20130102
H: \ wandoujia \ patch \ Quickplay _ 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 farmers .txt ------- 13913630 KB--------20130807
H: \ book \ 2014 \ Tang Yin in different circles \ Tang Yin in different boundaries .txt ------- 13328290 KB--------20130726
H: \ book \ 2014 \ the last day of the cockroach \ the last day when .txt ------- 13177834 KB--------20131129
H: \ book \ 2014 \ yijinjing .txt ------- 12995888 KB--------20130715
H: \ book \ 2014 \ anti-war red warning .txt ------- 12828979 KB--------20130928
H: \ book \ new \ channel .txt ------- 12445787 KB--------20130326
H: \ book \ 2014 \ 1895 gold rush country \ 1895taojin Guodu .txt ------- 12391071 KB--------20140104
H: \ book \ 2014 \ power minister .txt ------- 11949796 KB--------20130726
H: \ install \ 360weishi_167.apk ------- 11342128 KB--------20131009
H: \ book \ 2013.9.19 \ dash. 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 the folder size cannot be displayed.

There are two classes,

Package com. he. jinbin; import java. util. date;/*** used for sorting logic entity class ** @ author he Jinbin 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 ;}}
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;/*** main class used for sorting logic ** @ author he Jinbin QQ 277803242 **/public class Sort {public static List
 
  
FileItems = new ArrayList
  
   
(); Public static FileItem maxFileItem; public final static long M_1 = 1024*1024; public static long temp = M_1; // The public static void addFileItem (File file) of a File larger than 1 MB by default) {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 ("enter the address of the file to be sorted:"); BufferedReader inRd = new BufferedReader (new InputStreamReader (System. in); filePath = inRd. readLine (); System. out. print ("size of the input file to be sorted (unit: M):"); inRd = new BufferedReader (new InputStreamReader (System. in); temp = Long. parseLong (inRd. readLine () * M_1; inRd. close (); System. out. println ("running, please wait... "); File file = new File (filePath); addFileItem (file); SimpleDateFormat fmt = new SimpleDateFormat (" yyyyMMdd "); Collections. sort (fileItems); System. out. println ("sorting from large to small files:"); 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 ()));}}}
  
 

Although it is simple, my personal opinion is that programs are just tools. it is good programs to bring convenience to life, not to show technology, but to be practical.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.