In front of the file operation and the main interface, and then the file filtering and sorting, we all know that in our equipment, whether it is a PC or mobile phone, there are always some of our
Invisible folder, that is the so-called hidden files, most of the hidden files, we do not have permission to operate, all for us is not necessary, must kill,
There is to file list sorting, aspects of the search, in fact, in the current folder management, do not know if we have found that the interface is the most right or left
A A-Z vertical arrangement of options, click on each letter, it will jump to the beginning of the Word file list items to go, this is a more useful thing, because the app is the
Before it is useless to new things, let's talk about rough ones.
File Dictionary sort:
Package com.example.util;/** * File sort processing * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.util. Comparator;public class Customcomparator implements comparator<file>{@Overridepublic int compare (File pFile1, File pFile2) {/** * 1. Compare folders (folders above the order of files) 2. Sort by A-Z dictionary 3. Compare folders and files 4. Compare files and folders */if (Pfile1.isdirectory () && Pfile2.isdirectory ()) {return Pfile1.getname (). Comparetoignorecase (Pfile2.getname ());} else {if (pfile1.isdirectory () && pfile2.isfile ()) {return-1;} else if (Pfile1.isfile () && pfile2.isdirectory ()) {return 1;} else {re Turn pfile1.getname (). Comparetoignorecase (Pfile2.getname ());}}}
Filter hidden files:
Package com.example.util;/** * filter hidden files * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.io.Fi Lefilter;import Java.io.filenamefilter;public class Customfilefilter implements FileFilter {public Boolean accept (File DirName) {if (!dirname.getname (). StartsWith (".")) { return true;} Else{return false;}}}
Data sorting:
Package com.example.util;/** * Data sort * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.util.Ar Rays;import Java.util.collections;import Java.util.list;public class Filesort {public static file[] Sortfile (File[] files) {list<file> listfile = arrays.aslist (files); Collections.sort (ListFile, New Customcomparator ()); Make a sort by the specified rules file[] array = Listfile.toarray (new file[listfile.size ()); return array;}}
Example of sorting:
Sorting and filtering of files It's over, thank you.
Android Programming Starter Development Folder Manager development file filtering and sequencing-3