树状视图查看所有目录,例如在“ C:/”上

时间:2018-09-12 09:18:12

标签: java eclipse tree wicket root

我的树状视图有问题。我尝试创建一棵树来显示我的C:/-驱动器。在“ FooUtil”中,我已经开始通过将所有文件加载到集合中(通过file.listFiles())来创建新的Foos。然后,我遍历Collection,并为每个文件创建一个new Foo,并带有父级“ root”和fileName。现在我的问题是,你们是否可以创建一种算法来读取所有文件(及其子目录!)?这是我现在的代码:

    File[] fileCollection = null;

    String[] list = fileFolder.list();
    fileCollection = fileFolder.listFiles();

    ArrayList<File> tempfileList = null;
    ArrayList<File> fileList = null;

    if (fileCollection != null) {
        fileList = Lists.newArrayList(fileCollection);
    } else {
        fileList = Lists.newArrayList();
    }

    final IModel<List<File>> fileListModel = new ListModel<File>(fileList);
    //

    Foo[] fooz = new Foo[fileList.size()];
    int i = 0;
    int x = 0;
    // creating root
    Foo fooRoot = new Foo("root");
    // fooz[0] = new Foo("root");

    for (File file : fileListModel.getObject()) {
        // creating sub-directories in C:/
        fooz[i] = new Foo(fooRoot, file.getName());

        File tempFile = new File(file.getAbsolutePath());
        //
        if (tempFile.listFiles() != null) {
            tempFileCollection = tempFile.listFiles();
            tempfileList = Lists.newArrayList(tempFileCollection);
            Foo[] fooz2 = new Foo[tempfileList.size()];
            x = 0;

            for (File file2 : tempFileCollection) {
                fooz2[x] = new Foo(fooz[i], file2.getName());

             // here i could go for the next subdirectories

                x++;
            }

        }
        //
        i++;
    }
    foosy.add(fooRoot);
    return foosy;

0 个答案:

没有答案