First, getResourceAsStream in Java has the following types: 1. class. getResourceAsStream (String path): When the path does not start with '/', resources are retrieved from the package where the class is located by default. Resources starting with '/' are obtained from the ClassPath root. It only constructs an absolute path through path, and finally gets resources by ClassLoader. 2. Class. getClassLoader. getResourceAsStream (String path): It is obtained from the root of the ClassPath by default. The path cannot start with '/' and is finally obtained by the ClassLoader. 3. ServletContext. getResourceAsStream (String path): resources are retrieved from the WebAPP root directory by default. It doesn't matter if the path in Tomcat starts with '/'. Of course, this is related to the specific container implementation. 4. The application built-in object in Jsp is an implementation of the above ServletContext. Secondly, getResourceAsStream has the following usage: first, the files to be loaded and. the class file is in the same directory, for example, com. x. y has a class me. class with the resource file myfile. xml, the following code should be available: me. class. getResourceAsStream ("myfile. xml "); 2: in me. sub-directories in the class directory, such as com. x. y has a class me. class, at the same time in com. x. y. the file directory contains the resource file myfile. xml, the following code should be available: me. class. getResourceAsStream ("file/myfile. xml "); Third: Not me. the class directory is not in the subdirectory, for example: com. x. y has a class me. class, at the same time in com. x. the file directory contains the resource file myfile. xml, the following code should be available: me. CIA Ss. getResourceAsStream ("/com/x/file/myfile. xml "); To sum up, there may be only two ways to write first:"/"and"/"in front represent the root directory of the project. For example, the project name is myproject, "/" represents myproject me. class. getResourceAsStream ("/com/x/file/myfile. xml "); Second: No"/"above represents the directory me of the current class. class. getResourceAsStream ("myfile. xml "); me. class. getResourceAsStream ("file/myfile. xml "); finally, you can understand that the file path read by getResourceAsStream is limited to the source folder of the project, including under the src root directory of the project and any location in the class package, however, if the configuration file path is in a folder other than the source folder This method cannot be used.