views:

510

answers:

3

I've got a folder in my Web Application, fonts. I'd like to get the path for each of those files in that directory. How do I do that? In asp.net I'd do something like:


 System.IO.Directory.GetFiles(Server.MapPath("/fonts"))
+2  A: 
String path = ServletContext.getRealPath("/fonts");

Javadoc.

matt b
A: 
java.io.File dir = new java.io.File("/fonts");
String[] files = dir.list();
mamboking
A: 

You can use method getResourcePaths(String path) from ServletContext class for this purpose. It will return Set with directory-style listing of resources for specified (web-application mapped) path.

If you want to read content of file specified by mapped path, you can use method getResourceAsStream() from ServletContext returning InputStream for specified resource.

Matej