Java method example for reading files in the resource directory
This article mainly introduces the method of Java reading files in the resource directory. For example, this is the structure of your SRC directory
We want to test Read test. Java Txt file, we can use the resource class of guava library
The example code is as follows
The core function is resources Getresource, which actually encapsulates the following code:
The core logic of the above code is very simple, that is, obtain the resource file by obtaining the classloader
If you want to introduce Google's guava library, if you use Maven project, you can use POM Add the following code to XML:
summary
The above is all about Java reading the files under the resource directory. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.