File
is Serializable
, and a FileTreeModel
that implements TreeModel
is straightforward, as mentioned here. You can traverse a tree rooted in File f
using code like this:
private void ls(File f) {
File[] list = f.listFiles();
for (File file : list) {
if (file.isDirectory()) ls(file);
else handle(file);
}
}
Also consider Bloch's suggestion, Item 75, "Do not accept the default serialized form without first considering whether it is appropriate."