- <span style="FONT-SIZE:18PX;" >file[] Files =parentfile.listfiles (filefilter); //By Filefileter filter to get the desired type of sub-file under the Parentfile path
- arraylist<fileinfo> fileList = new arraylist<fileinfo> (); Deposit the required sub-file information into FileInfo
- For (int i = 0; i < files.length; i++) {
- File file = Files[i];
- FileInfo FileInfo = new FileInfo ();
- Fileinfo.name = File.getname ();
- Fileinfo.path = File.getpath ();
- Fileinfo.lastmodified= file.lastmodified ();
- Filelist.add (FileInfo);
- }
- Collections.sort (FileList, new Filecomparator ()); By overriding comparator implementation class Filecomparator, you can sort by file creation time.
- Report:
- Public class Filecomparator implements comparator<fileinfo> {
- public int compare (FileInfo file1, FileInfo file2) {
- if (file1.lastmodified < file2.lastmodified)
- {
- return-1;
- }Else
- {
- return 1;
- }
- }
- }
- Public FileFilter filefilter = new FileFilter () {
- Public Boolean accept (file file) {
- String tmp = File.getname (). toLowerCase ();
- if (Tmp.endswith (". mov") | | tmp.endswith (". jpg")) {
- return true;
- }
- return false;
- }
- };</span>
Similarly: By overriding the Compare method in the comparator implementation class, the display is arranged by file size, file name, and so on.
How Android implements files in chronological order display