Hello,
I am tried a similar program like this. Here is the source code I have tried till now. If you find any problems in the code then please guide me.
Code:
Public class NameComparator implements Comparator, Serializable{
Public int compares(Object filen1, filen2 Object){
int res =0;
File f1 = (File)filen1;
File f2 = (File)filen2;
String n1 = f1.getName();
String n2 = f2.getName();
if(n1.equals("Parent Directory")) res = 1;
else if(n2.equals("Parent Directory")) res = -1;
else if(f1.isDirectory() & & File2.isFile()) res = -1;
else if(f2.isDirectory() & & File1.isFile()) res = 1;
else if(f1.isDirectory() & & File2.isDirectory()) {
if(n1.compareTo(n2) > 0) res = 1;
}
else if(f1.isFile() & & File2.isFile()) {
if(n1.compareTo(n2) > 0) res = 1;
}
if(n1.compareTo(n2) > 0) res = 1;
else res =-1;
/ / System.out.println (n1 + "comparedto" + n2 + "" + String.valueOf (res));
return res;
}
Bookmarks