Resource下的配置文件路径IO读取问题

RedisClient.class.getResource("/jedisPool.properties").getPath()可获得Resource下的配置文件路径

static {
		Reader reader;
		Properties properties=new Properties();
		try {
			
			reader = new InputStreamReader(new FileInputStream(RedisClient.class.getResource("/jedisPool.properties").getPath()), "UTF-8");
			
			properties.load(reader);
			JedisPoolConfig config=new JedisPoolConfig();
	        config.setMaxTotal(Integer.parseInt(properties.getProperty("MAX_TOTAL")));
	        config.setMaxIdle(Integer.parseInt(properties.getProperty("MAX_IDLE")));
	        config.setMaxWaitMillis(Integer.parseInt(properties.getProperty("MAX_WAIT")));
	        config.setTestOnBorrow(Boolean.getBoolean(properties.getProperty("TEST_ON_BORROW")));
	        //这里我的redis数据库没有设置密码所以不需要密码参数,否则可以添加密码参数
	        //jedisPool=new JedisPool(config,ADDR,PORT,TIMEOUT,AUTH);
	        jedisPool=new JedisPool(config,properties.getProperty("ADDR"),Integer.parseInt(properties.getProperty("PORT")),Integer.parseInt(properties.getProperty("TIMEOUT")));
		} catch (UnsupportedEncodingException | FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        
        


	}
发布了28 篇原创文章 · 获赞 7 · 访问量 8606

猜你喜欢

转载自blog.csdn.net/qq_35953966/article/details/90142504