Java reads properties files
The file name is db.properties
The first one is obtained through ResourceBundle
ResourceBundle bunble = ResourceBundle.getBundle ("db")
Driver = bunble.getString ("driver")
Url = bunble.getString ("url")
Username = bunble.getString ("username")
Password = bunble.getString ("password")
The second is to obtain / / 1 through the class loader. Get the access method of class loader through the current class: type .class.getClassLoader () ClassLoader classLoader = JDBCUtils_V3.class.getClassLoader (); / / 2. Get an input stream InputStream is = classLoader.getResourceAsStream ("db.properties") through the class loader; / / 3. Create the properties object Properties p = new Properties (); / / 4. Load the input stream p.load (is); / / 5. Get the values of related parameters driver = p.getProperty ("driver"); url = p.getProperty ("url"); username = p.getProperty ("username"); password = p.getProperty ("password")