//创建Properties对象 Properties properties = new Properties(); //获取类加载器 ClassLoader loader = baseDao.class.getClassLoader(); //通过类加载器加载资源文件为字节输入流 InputStream in = loader.getResourceAsStream("db.properties"); try { properties.load(in); } catch (IOException e) { e.printStackTrace(); } //获取db.properties资源 DRIVER = properties.getProperty("DRIVER"); URL = properties.getProperty("URL"); USERNAME = properties.getProperty("USERNAME"); PASSWORD = properties.getProperty("PASSWORD");