Java file path reading and java path reading
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.
How can I obtain the relative path when writing a file in java?
Jar files can only be read and cannot be written.
How does java obtain the path in the browser file box?
In jsp, give the text an id, and then give the test button an event in jsp. Click it to get the text field value through getElementById (id), and then pass it to the background.