Hi there,
I am trying to list files and directories within an war-file i.e
images/summer2010 images/winter2010. The war-file is deployed on a
tomcat 7 instance with unpackWARs="false".
Since I have no exposed filesystem getRealPath will return null. So I
tried to use getResourceAsStream wich works fine for files but not for
directories.
My other idea was to use getResource and URL/URI to get a java.io.File
via JNDI. But this file is not a file nor a directory.
Cheers
Darky
Code Snippet:
// null if unpackWar = false
String absolute =
this.getServletConfig().getServletContext().getRealPath("files");
out.write("Files: " + absolute);
// jndi
URL url =
this.getServletConfig().getServletContext().getResource("files");
out.write("<br/>" + url.toURI());
File f = new File("file:" + url.toURI());
// Both null
out.write(" isDir: " + f.isDirectory());
out.write(" isFile: " + f.isFile());
InputStream is =
this.getServletConfig().getServletContext().getResourceAsStream("files/1.txt");
// NPE if directory
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
out.write("<br/>content<br/>");
while ((line = br.readLine()) != null) {
// print file content
out.write(line +"<br/>");
}
br.close();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]