从linux目录结构创建树

时间:2013-01-27 20:12:50

标签: java

我需要从linux目录结构创建一个树。例如:

. 0
./file1.txt 1
./file2.txt 2
./site 3
./site/file3.txt 4
./site/ru 5
./site/ru/file4.txt 6

每个节点都是目录或文件(如果没有子节点)并且具有ID(> = 0)。根ID为0.父ID始终低于子ID。我创建了两个类:

class Node<T1, T2> {
    T1 key;
    T2 value;

    List<Node<T1, T2>> children;

    Node(T1 key, T2 value) {
        this.key = key;
        this.value = value;
        children = new ArrayList<Node<T1, T2>>();
    }

    public boolean isFile()
    {
        return children.size() == 0;
    }
}

public class DirectoryTree<T1 extends Comparable<T1>, T2> 
{
   private Node<T1, T2> root = null;

   public DirectoryTree(T1 key, T2 value)
   {
       root = new Node<T1, T2>(key, value);
   }
}

如何填充树?

0 个答案:

没有答案