java - 树视图查看所有目录,例如“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;
解决方案
推荐阅读
- javascript - 内联 JS 在移动设备上产生 2 个新窗口
- javascript - 反应:在移动浏览器按钮 onClick hadler 触发多次。台式机没问题
- c# - 我对 sql 数据库及其视图逻辑有疑问?
- git - 当签出和推送回购的不同分支时,您计算机上的明显文件如何变化?
- python - set_camera_info 在 ubuntu 16.04 上不适用于 ROS
- python - 迁移学习 - 尝试在 RTX 2070 上重新训练efficientnet-B07 内存不足
- odoo - 在向导中显示模型的 one2many 值
- django - Django Machina 模板面临的问题
- typescript - 可以在 Typescript 中导出导入的合并命名空间吗?
- python - 难以让我的代码正确运行