public class Liste2
{
ArrayList<String> files = new ArrayList<String>();
Date date;
public Liste2(File f)
{
sucheOrdner(f);
Collections.sort(files);
System.out.println("Liste erstellt: \t" + files.size() + " Ordner, " + files);
speichereListe();
}
private void sucheOrdner(File f)
{
File[] root = f.listFiles();
if ((root = f.listFiles()) != null)
{
for (int i = 0; i < root.length; i++)
{
if (root[i].isDirectory())
{
files.add(root[i].getPath());
sucheOrdner(root[i]);
}
}
}
}
private void speichereListe()
{
ObjectOutputStream o = null;
try
{
OutputStream fos = new FileOutputStream("file_liste.ser");
o = new ObjectOutputStream(fos);
o.writeObject(new Date());
o.writeObject(files);
}
catch (IOException ex)
{
Logger.getLogger(Liste2.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
o.close();
}
catch (IOException ex)
{
Logger.getLogger(Liste2.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private ArrayList<String> leseListe()
{
ArrayList<String> files_alt = null;
ObjectInputStream o = null;
try
{
InputStream fis = new FileInputStream("file_liste.ser");
o = new ObjectInputStream(fis);
date = (Date)o.readObject();
files_alt = (ArrayList<String>)o.readObject();
}
catch (IOException ex)
{
Logger.getLogger(Liste2.class.getName()).log(Level.SEVERE, null, ex);
}
catch (ClassNotFoundException ex)
{
Logger.getLogger(Liste2.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
o.close();
}
catch (IOException ex)
{
Logger.getLogger(Liste2.class.getName()).log(Level.SEVERE, null, ex);
}
}
return files_alt;
}
public void vergleicheListe()
{
ArrayList<String> files_alt = leseListe();
System.out.println("lese: " + files_alt);
for (String s : files)
{
System.out.println("s: " + s + " -> " + Collections.binarySearch(files_alt, s));
if (Collections.binarySearch(files_alt, s) < 0)
{
System.out.println(s + " wurde gelöscht");
}
}
}
public static void main(String[] args)
{
Liste2 l = new Liste2(new File("C:/temp/a"));
l.vergleicheListe();
}
}
-----
Liste erstellt: 2 Ordner, [C:\temp\a\b, C:\temp\a\c]
lese: [C:\temp\a\b, C:\temp\a\c]
s: C:\temp\a\b -> 0
s: C:\temp\a\c -> 1