首页 > 解决方案 > 树视图查看所有目录,例如“C:/”

问题描述

我的树视图有问题。我尝试创建一棵树来显示我的 C:/- 驱动器。在“FooUtil”中,我已经开始通过将所有文件加载到集合中(通过file.listFiles())来创建新的 Foo。然后我遍历Collection和为我创建的每个文件new Foo,父“根”和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;

标签: javaeclipsetreewicketroot

解决方案


推荐阅读