use*_*218 5 java directory web-applications data-structures
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));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
目录结构很容易用树来建模。您可以认为每个节点代表一个目录或文件,边从目录延伸到该目录的内容。
您可以通过一个节点类来表示树本身,该节点类存储实体(目录或文件)的名称(无论它是否是目录),以及从其子目录/文件的名称到这些子目录的节点的映射,或者文件。
希望这可以帮助!