Remember to learn in the operating system file read in two ways Of course, this is also in each programming language is a generic so java path also divided into relative and absolute path.
Absolute Path
the absolute path URI , which sounds very similar to the URL . then let's take a look at it.
URI(uniformresource Identifier) Uniform Resource Identifier . The URL Uniform Resource Locator , which is a locator , also explains how to find resources in detail . so they have an abstract and inherited relationship. URIAbstract description of theUniform Resource representation symbols, while the URLis the detailed identifier of the way.
How to use it.
If we want to get a detailed location for a class. Just for example, in the following ways:
For example: Test . Class. Getresouce ("");
Suppose the middle adds "/",Test. class. Getresouce ("/"); Gets the Java class followed by the folder.
The two are different.
relative Path
is generally relative to an absolute path , we often use relative to ClassPath.
such as: The use of ClassLoader class getresouce() and other methods. The current classPath relative path is obtained.
URL Ds=thread.currentthread (). Getcontextclassloader (). GetResource (""); System.out.print (ds+ "\ n"); System.out.print (Classloader.getsystemresource (""));
Two kinds of results are the same .
to read content , directly using a byte stream file
InputStream In=classloader.getsystemresourceasstream ("Beanx-config.xml");
ClassLoader is a class loader that can specify the loading of special resources . Why the same? . The reason is thatThread.CurrentThread ()sets the currentClassLoader.They both specify the default path.so the two paths are equally.
Overall Understanding :
URL uri uri is a semantic abstraction that can be absolute and relative. and url relative URL absolute URL
Read the Java file path