配置文件的读取
(1)配置文件放在项目的根目录下
Properties properties = new Properties(); InputStream is = new FileInputStream("config.properties"); // 导入输入流 properties.load(is); // 读取 driverClass = properties.getProperty("driverClass"); url = properties.getProperty("url"); username = properties.getProperty("username"); password = properties.getProperty("password");
(2)配置文件放在src目录下
Properties properties = new Properties(); InputStream is = JDBCutils.class.getClassLoader().getResourceAsStream("config.properties"); // 导入输入流 properties.load(is); // 读取 driverClass = properties.getProperty("driverClass"); url = properties.getProperty("url"); username = properties.getProperty("username"); password = properties.getProperty("password");
代码成就万世基积沙镇海,梦想永在凌云意意气风发。