Remember that there are two ways to read files in the operating system, of course, this is also common in various programming languages, so the java path is also divided into relative and absolute paths. The absolute path is the absolute path URI. it looks very similar to the URL. let's take a look. URI (UniformresourceIdentifier) is a uniform resource identifier. the URL is a uniform resource identifier and also describes how to find resources.
Remember that there are two ways to read files in the operating system, of course, this is also common in various programming languages, so the java path is also divided into relative and absolute paths.
Absolute path
The absolute path URI. it looks very similar to the URL. let's take a look.
URI (Uniformresource Identifier) is a uniform resource Identifier. URL is a uniform resource Identifier. It also describes how to find resources, so they have an abstract and inheritance relationship. The URI abstraction specifies the uniform resource representation, while the URL is a specific identifier.
How to use it. For example, we want to obtain the specific position of a class. As long as the method is as follows:
For example:Test. class. GetResouce ("");
If"/", Test. class. GetResouce ("/"); obtains the Directory of the java class. The two are different.
Relative path
It is usually relative to an absolute path. we often use ClassPath.
For example, use the getResouce () method of the ClassLoader class to obtain the relative path of the current classPath.
URL ds=Thread.currentThread().getContextClassLoader().getResource("");System.out.print(ds+"\n");System.out.print(ClassLoader.getSystemResource(""));
The two results are the same.
To read the content, use the byte stream file directly.
InputStream in=ClassLoader.getSystemResourceAsStream(""beanx-config.xml"");
ClassLoader is a class loader that can be specified to load special resources. why is it the same. the reason is Thread. currentThread () sets the current ClassLoader. they all specify the default path. therefore, the two are in the same path.
Overall understanding:
A url is a specific URI that not only uniquely identifies a resource, but also provides information for locating the resource. URI is a semantic abstract concept. it can be absolute or relative, while URL must provide sufficient information for locating. Therefore, it is absolute, generally, the relative URL is targeted at another absolute URL, which is basically absolute.