For example, we need to load the db. properties file under the source directory. There are the following methods: file io stream: copy the code public static void load1 () throws Exception {// true file path String fileName = "E: /Workspace/SSHDemo/Source/db. properties "; Properties p = new Properties (); InputStream is = new FileInputStream (new File (fileName); p. load (is); System. out. println (p);} copy the second type of code: Relative Path: copy the code // relative path public static void load2 () throws Exception {Properties p = new Properties (); // InputStream is = ClassLoader. getSyst EmResourceAsStream ("db. properties "); InputStream is = Thread. currentThread (). getContextClassLoader (). getSystemResourceAsStream ("db. properties "); p. load (is); System. out. println (p);} public static void load2_1 () throws Exception {Properties p = new Properties (); InputStream is = SourceLoader. class. getClassLoader (). getSystemResourceAsStream ("db. properties "); p. load (is); System. out. println (p);} copy the Code if we want to obtain What should I do with db. properties under src (class package? Copy the code // put java together with the properties file box of the class path public static void load3 () throws Exception {Properties p = new Properties (); // InputStream is = ClassLoader. getSystemResourceAsStream ("db. properties "); InputStream is = SourceLoader. class. getResourceAsStream ("db. properties "); p. load (is); System. out. println (p );