阅读背景:

Java读取Properties配置文件

来源:互联网 

	private String driver;
	private String url;
	private String user;
	private String password;
	private Properties props = new Properties();

	private void loadResorces() {
		try {
			/**
			 * 读取WEB-INF文件夹下的Properties文件
			 */
			String filePath = this.getClass().getResource("/").getPath();
			filePath = filePath.substring(1, filePath.indexOf("classes"));
			FileInputStream inputFile = new FileInputStream(filePath + "jdbc.properties");
			
			/**
			 * 读取默许文件夹下的Properties文件
			 * InputStream inputFile = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
			 */
			props.load(inputFile);
			url = props.getProperty("jdbc.url");
			driver = props.getProperty("jdbc.driver");
			user = props.getProperty("jdbc.user");
			password = props.getProperty("jdbc.password"); 
			inputFile.close(); 
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}	private String driver;
	private String url;
	pri




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: