Use the example below, run sort with Java
1, enter the path of the file you want to sort, such as an example of a file under H:\ and all of its subfolders.
2, enter the latest size that you want to sort the display, such as an example of sorting files above 10M size
3, from large to small sort after pressing
File path \ filename-------size KB--------creation date display (YYYYMMDD)
Format to display the.
So you can delete too large files and clean up the space.
Run Example: H disk point to my cell phone memory card
Copy Code code as follows:
D:\hjbssorft\work\20140207\sortsize\bin>java Com.he.jinbin.Sort
Enter the desired sort file address: h:\
Enter required sort file size (unit m): 10
In operation, please wait a moment ...
Sort from large to small files 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
Copy Code code as follows:
Package com.he.jinbin;
Import Java.util.Date;
/**
* Used to sort logical entity classes
*/
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 Code code as follows:
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; The
/**
* is used to sort the logical main class
*/
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;//default file greater than 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 ("Input needs to sort file address:");
BufferedReader inrd = new BufferedReader (New InputStreamReader (
system.in));
FilePath = Inrd.readline ();
System.out.print ("Input needs to sort file size (unit m):");
INRD = new BufferedReader (new InputStreamReader (system.in));
temp = Long.parselong (Inrd.readline ()) *m_1;
Inrd.close ();
System.out.println ("In operation, please wait a moment ...");
File File = new file (FilePath);
Addfileitem (file);
SimpleDateFormat FMT = new SimpleDateFormat ("YyyyMMdd");
Collections.sort (Fileitems);
System.out.println ("From large to small files sorted as:");
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 ());
}
}
}