How do I retrieve the path to a file?

shadie
shadie used Ask the Experts™
on
I have developed some code on a local server that uses a DSN-less connection to an Access Database. Everything works fine because I know the exact path to the database:

Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Inetpub/DB/AccessDB.mdb","","");

The trouble I am now running into is finding out the exact path to the file when I upload it to my live server. I have asked my site developers but they have not been so forthright with the information. I found an example in a JSP book that will list the contents of a directory like c:\Inetpub or c:\Program Files. For some reason, I am not able to use this knowledge to get all the way to the file I need (the database). See code below.

Is there any way you can post a jsp to a directory that when run will give you the exact path where it lives on the server? It would return something like: c:\Inetpub\wwwroot\db\AccessDB.mdb

Would it be an adaptation of the code below or is that going in the wrong direction?

<html>
<head>
<title>display a directory listing</title>
</head>
<body bgcolor="#ffffff">
<%@ page import = "java.io.*" %>
<h1>Directory Listing</h1>
<ul>
<%
File dataDir = new File("c:");
File[] listing = dataDir.listFiles();

for(int x = 0; x < listing.length; x++)
     out.print("<li>" + listing[x] + "</li>");
%>
</ul>
</body>
</html>

Thanks in advance!
Jon
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
>Is there any way you can post a jsp to a directory that when run will give you the exact path where it lives
you could use
<%=application.getRealPath(request.getServletPath())%>

Author

Commented:
Thanks for a speedy response!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial