Corresponding to the root directory of the absolute path: request.getRequestURI ()
Document's absolute path: application.getRealPath (request.getRequestURI ());
The current web application's absolute path: application.getRealPath ("/");
Made the request of the parent directory file: new File (application.getRealPath (request.getRequestURI ())). getParent ();
2.Servlet access to current applications in the relative path and absolute path
Corresponding to the root directory of the absolute path: request.getServletPath ();
Document's absolute path: request.getSession (). GetServletContext (). GetRealPath
(request.getRequestURI ());
The current web application's absolute path: servletConfig.getServletContext (). GetRealPath ("/");
ServletContext object access in several ways:
Javax.servlet.http.HttpSession.getServletContext ()
Javax.servlet.jsp.PageContext.getServletContext ()
Javax.servlet.ServletConfig.getServletContext ()
3. To obtain the current class in which jar package path:
URL uri = clazz.getProtectionDomain().getCodeSource().getLocation(); String path = uri.getPath(); File jarFile = new File(path);
4.windows access to the desktop folder:
FileSystemView fileSystemView =FileSystemView.getFileSystemView();File[] desktops = fileSystemView.getRoots();
5. Access to My Documents:
FileSystemView fileSystemView =FileSystemView.getFileSystemView(); File f = fileSystemView.getDefaultDirectory();
Above two options, in the void under vista, because vista desktop, my documents path with xp, 2000 not the same.
6. Server access to the Java type of the current path
(1) Weblogic
WebApplication the document root of the system is installed where the root directory of weblogic
For example: If you have weblogic installed in c: \ bea \ weblogic700 .....
In that case, your document root path is c: \.
Therefore, there are two ways to let you access your server-side document:
a. use an absolute path:
For example, the parameters of your document on the c: \ yourconfig \ yourconf.properties,
Direct the use of new FileInputStream ( "yourconfig / yourconf.properties");
b. the use of relative path:
Relative path is the root of the root of your webapplication path, that is, on the WEB-INF directory level, the parameters of your document yourwebapp \ yourconfig \ yourconf.properties,
Such use:
new FileInputStream ( ". / yourconfig / yourconf.properties");
This can be in two ways, of their choice.
(2) Tomcat
Output in class System.getProperty ( "user.dir"); shows% Tomcat_Home% / bin
7. To obtain the implementation of the current file path:
String dir = System.getProperty("user.dir"); Through the System.getProperty () also can be a lot of environmental parameters, the following is a table before finishing.
java.version Java Runtime Environment version
java.vendor Java Runtime Environment supplier
java.vendor.url Java supplier URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine Specification suppliers
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine version
java.vm.vendor Java Virtual Machine suppliers
java.vm.name Java Virtual Machine Name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification suppliers
java.specification.name Java Runtime Environment specification name
java.class.version Java type format version number
java.class.path Java classpath
java.library.path load library path search list
java.io.tmpdir Default temp file path
java.compiler want to use the name of JIT compiler
java.ext.dirs directory of one or more of the expansion path
the name of the operating system os.name
the structure of the operating system os.arch
version of the operating system os.version
file.separator paper separator (in the UNIX system is "/")
path.separator Path separator (in the UNIX system is ":")
line.separator Line separator (in the UNIX system is "/ n")
user.name User account name
user.home User's home directory
user.dir User's current working directory








Responses to “Java variety of paths and parameters”