What is the servlet equivalent of Server.MapPath?

I have a folder in my web application, fonts. I would like to get a path for each of these files in this directory. How can I do it? In asp.net, I would do something like:


 System.IO.Directory.GetFiles(Server.MapPath("/fonts"))
+3
source share
3 answers
String path = ServletContext.getRealPath("/fonts");

Javadoc .

+6
source

For this purpose, you can use the getResourcePaths (String path) method from the ServletContext class. It will return a Set with a resource list directory for the specified (bound to the web application) path.

, , getResourceAsStream() ServletContext, InputStream .

0
java.io.File dir = new java.io.File("/fonts");
String[] files = dir.list();
-1
source

Source: https://habr.com/ru/post/1709788/


All Articles