My webapp is running from Tomcat, installed on a Windows machine. I want the servlet to find out the drive letter (eg. C: or D: etc) programmatically, on which my Tomcat is installed.
Asked
Active
Viewed 142 times
2 Answers
0
To find out the installation directory of an application.
you can search the registry
see read/write to Windows Registry using Java.
I uses jregistrykey.

Community
- 1
- 1

Surinder ツ
- 1,778
- 3
- 16
- 27
0
First you need a place where a ServletContext is present. That might be a Servlet, ContextListener, Filter or maybe a JSP. Than, you can use this to find the root of the current drive:
File dir = new File(getServletContext().getRealPath(""));
while (dir.getParentFile() != null) {
dir = dir.getParentFile();
}
System.out.println("Current root directory: " + dir);

Stefan
- 12,108
- 5
- 47
- 66