Classloader provides two methods for obtaining resources from the loaded class path:
Public URL getresource (string name );
Public inputstream getresourceasstream (string name );
Here name is the class path of the resource, which is relative to the location under the "/" root path. Getresource obtains a URL object to locate the resource, while getresourceasstream obtains the reference guarantee of the resource input stream.ProgramData can be extracted from the correct location.
But when I call these two methods for the first time, I fail to get the resources I want. In the past, we used not the classloader methods, but the getresource and getresourceasstream methods of the class, because the class object can be obtained from your class (such as yourclass. class or yourclass. getclass (), while classloader needs to call yourclass again. the getclassloader () method, but according to the JDK documentation, the two methods of the class object are actually "delegated" (delegate) to the classloader that loads it, therefore, you only need to use the two methods of the Class Object.
Conclusion: call this. getclass. getresourceasstream (string name) to obtain a positive solution.