数据结构存储目录结构? [英] Data structure to store a directory structure ?
问题描述
我的问题是要使用的数据结构为了存储目录结构,使JSP页面可以从action类访问该目录结构对象。
ps:我想使用以下java代码遍历目录。
Plz help
import java.io.File;
public class DisplayDirectoryAndFile {
public static void main(String args []){
displayIt(new File(C:\\\ ));
}
public static void displayIt(File node){
System.out.println(node.getAbsoluteFile());
if(node.isDirectory()){
String [] subNote = node.list();
(String filename:subNote){
displayIt(new File(node,filename));
}
}
}
}
目录结构非常容易被树木建模。您可以想到表示目录或文件的每个节点,边缘从目录运行到该目录的内容。
您可以通过使用节点类来表示树本身存储实体的名称(目录或文件),无论它是否是目录,以及从其子目录/文件的名称到这些子目录或文件的节点的映射。
希望这有帮助!
I am developing a simple java web application using struts 2 framework. the purpose of the application is to display a specific directory structure under my computer using a JSP page.
My question is which data structure to use in order to store a directory structure, so that the JSP page can access that directory structure object from the action class.
ps:I want to use the following java code to traverse the directory.
Plz help
import java.io.File;
public class DisplayDirectoryAndFile{
public static void main (String args[]) {
displayIt(new File("C:\\Downloads"));
}
public static void displayIt(File node){
System.out.println(node.getAbsoluteFile());
if(node.isDirectory()){
String[] subNote = node.list();
for(String filename : subNote){
displayIt(new File(node, filename));
}
}
}
}
Directory structures are very easily modeled by trees. You can think of each node representing a directory or file, with edges running from directories to the contents of that directory.
You could represent the tree itself by having a node class that stores the name of the entity (directory or file), whether or not it is a directory, and a map from the names of its subdirectories / files to the nodes for those subdirectories or files.
Hope this helps!
这篇关于数据结构存储目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!