älteste Datei in einem Verzeichnis finden

Hi,
ich überprüfe, ob ein Verzeichnis Files enthält. Wenn ja, dann soll das älteste File bearbeitet werden.
Bisher habe ich nur die Überprüfung:

public static boolean searchDirectory()
{
 boolean result = false;
 String s = "";

 try
 { 
 //ACHTUNG nur Windows!!!
 // user.dir gibt das aktuelle Arbeitsverzeichnis zurück. 
 File dir = new File(System.getProperty("user.dir")+ "\\in\\");
 String[] list = dir.list(); 

 if (list.length \> 0)
 {
 System.out.println ("Dateien gefunden");
 --\> hier jetzt die älterste Datei finden
 return true; 
 }

 else return false;
}
 catch ( Exception e ) 
 { 
 System.out.println(e);
 return false;
 } 
}

Ideen?
Steffi

Moin.

Ich hatte mal so ein aehnliches Problem und habe es
so geloest:

public class XYZ {
 ...
 public static boolean searchDirectory()
 ....
 System.out.println ("Dateien gefunden");

 // --- get file list and sort it by lastModified
 // --- afterwards the first one (index 0) is the oldest file
 File[] fileList = dir.listFiles();
 Arrays.sort(fileList, new CompareTime());

 return true;
 ...
 } // searchDirectory()
 ...
 private class CompareTime implements Comparator {
 public int compare(Object f1, Object f2) {
 if (f1 instanceof File && f2 instanceof File) {
 Long l1 = new Long(((File) f1).lastModified());
 Long l2 = new Long(((File) f2).lastModified());
 return l1.compareTo(l2);
 }
 return 0;
 }
 }
} // end of main class

Das geht bestimmt einfacher, aber so funktioniert es zumindest
schonmal.

Gruss, Patrick

danke - das test ich mal! o.T.
hi Patrick,
vielen Dank, das teste ich doch mal aus!

steffi