When writing a JSP file, how can I get the current directory of this file at runtime
(to be able to iterate the directory and list its contents)?
<%@page import="java.io.*" %>
<%@page import="java.util.*" %>
<%! public void GetDirectory(String a_Path, Vector a_files, Vector a_folders) {
File l_Directory = new File(a_Path);
File[] l_files = l_Directory.listFiles();
for (int c = 0; c < l_files.length; c++) {
if (l_files[c].isDirectory()) {
a_folders.add(l_files[c].getName());
} else {
a_files.add(l_files[c].getName());
}
}
}
%>
<%
Vector l_Files = new Vector(), l_Folders = new Vector();
GetDirectory("C:/mydirectory/", l_Files, l_Folders);
//folders should be left out...
//for( int a = 0 ; a"+l_Folders.elementAt(a).toString() + "]
") ;
//generate files as XML
out.println("");
for (int a = 0; a < l_Files.size(); a++) {
out.println("" + l_Files.elementAt(a).toString() + " ");
}
out.println(" ");
%>
Replace "C:/mydirectory/" with your directory