. GetResourceAsStream reads the configuration file Thread.currentThread (). GetContextClassLoader ()

Java with a path into the relative and absolute paths;

Also divided into four categories:

The absolute path in the form of 1.URI 

  如:file:/D:/java/eclipse/workspace/j/bin/a

  URI including URL and URN two categories, URL is a subset of URI, so the URL must be a URI, and the URI is not necessarily a URL

  URL is a special case of URI (a standard URL must include: protocol, host, port, path, parameter, anchor)

  URL prefix / protocol, you must be familiar with Java. URL can open the resource, and URI is not. URL and the URI object can be converted to each other using respective toURI (), toURL () method may be!

2. Absolute path to the local system

  D:/java/eclipse/workspace/j/bin/a

  Java.io package classes, the need to use this form of parameters.

  However, they generally offer a type of URI parameters, and the type of URI parameters, accept that URI pattern String. Thus, the URI converting, or can be the absolute URI path pattern used in java.io package classes

3. classpath relative path corresponding to

  Such as: relative

  file: / D: / java / eclipse / workspace / j / relative path bin / the path. Which, bin is the project classpath. Copy all Java source files compiled .class files into this directory .

4 corresponds to the user relative to the current directory

  Return path is relative to System.getProperty ( "user.dir")

  By default, java.io classes in a package is always based on the current user directory to analyze the relative path name. This user.dir directory specified by the system property, usually called Java virtual machine. That is to say, in use

When java.io package classes, best not to use a relative path.

Here are some methods to get the absolute path of the current classpath and class of:

1.FileTest.class.getResource ( "") is obtained by URI class FileTest.class directory of the current file. Not including yourself!

如:file:/D:/java/eclipse32/workspace/jbpmtest3/bin/com/test/

2.FileTest.class.getResource ( "/") obtained an absolute URI path of the current classpath.

Such as: File: / D: / the Java / eclipse32 / Workspace / jbpmtest3 / bin /

3.Thread.currentThread () getContextClassLoader () getResource absolute URI paths are obtained current ClassPath ( "")...

Such as: File: / D: / the Java / eclipse32 / Workspace / jbpmtest3 / bin /

4.FileTest.class.getClassLoader () getResource absolute URI path ( "") is obtained in the current ClassPath.

Such as: File: / D: / the Java / eclipse32 / Workspace / jbpmtest3 / bin /

5.ClassLoader.getSystemResource ( "") absolute URI path is the current ClassPath obtained.

如:file:/D:/java/eclipse32/workspace/jbpmtest3/bin/

URI recommended Thread.currentThread (). GetContextClassLoader (). GetResource ( "") to get the absolute path of the current classpath representation.

 

Guess you like

Origin www.cnblogs.com/lingxi2b2/p/12063623.html