【发布时间】:2021-07-15 09:14:57
【问题描述】:
我正在尝试做一个 primefaces 树节点,它显示包含一个目录的文件或目录的名称。这是我目前得到的。
问题是代码将节点保存到前一个节点,但我想要的是,如果我们传递给列表中的下一个值,它会检查 p.example 节点 C:/ 是否存在,如果它存在,它会检查如果其中的下一个节点存在,如果存在,则递归执行相同的操作。
public void init() {
root = new DefaultTreeNode("Files", null);
try (Stream<Path> paths = Files
.walk(Paths.get("C:\\Path"))) {
List<String> list = paths.map(path -> Files.isDirectory(path) ? path.toString() + '/' : path.toString())
.collect(Collectors.toList());
for (int i = 0; i < list.size(); i++) {
String[] prueba = list.get(i).split("\\\\");
List<String> listaprueba = new ArrayList<String>(Arrays.asList(prueba));
//removes C:/
listaprueba.remove(0);
prueba = listaprueba.toArray(new String[0]);
for (int e = 0; e < prueba.length; e++) {
if (root.getChildCount() == 0) {
setNode0(new DefaultTreeNode(prueba[0], root));
} else {
if (prueba[e].equals(prueba[prueba.length - 1])) {
node0.getChildren().add(new DefaultTreeNode(prueba[e], node0));
} else {
setNode0(new DefaultTreeNode(prueba[e], node0));
}
}
}
}
}
catch (
IOException e) {
System.out.println("Archivo no encontrado.");
}
}
【问题讨论】:
标签: java jsf primefaces