Wednesday, 11 July 2012

Sort directory/file in order of lastModified time

Last exercise describe how to Sort directory/file in alphabetical order ignore case. To Sort directory/file in order of lastModified time, replace filecomparator() method of last exercise with following code:

    Comparator<? super File> filecomparatorByLastModified = new Comparator<File>(){

public int compare(File file1, File file2) {

if(file1.isDirectory()){
if (file2.isDirectory()){
return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
}else{
return -1;
}
}else {
if (file2.isDirectory()){
return 1;
}else{
return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
}
}

}
};


Download the files.

Next:
- File Explorer with sorting, in alphabetical and lastModified.


Borneo08

About Borneo08

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :

More links

Related Posts Plugin for WordPress, Blogger...