This may sound like a really simple problem but I can't figure out a way around this.
I have a config.properties file which contains two key values: an IP address and a Port number. I read this config file to extract the key values in string format. However, when I am trying to use these values, I am unable to connect to the IP address retrieved from the config file.
The reason is that the values read are in string format and I need to convert them to proper formats before using them. What I want is that the value "192.168.1.40" stored in config file is converted to a String host format. I tried using InetAddress but that gives an error.
The contents of the config file are:
IP=192.168.1.40
PORT=9124
The code that uses these values is as follows:
Properties prop = new Properties();
String propFileName = "...//testJedis//resources//config.properties";
prop.load(new FileInputStream(propFileName));//testJedis/resources/config.properties"));// configStream);
Jedis jedis=new Jedis(prop.getProperty("IP"),Integer.parseInt(prop.getProperty("PORT")));
//Jedis jedis = new Jedis("192.168.1.40",9124);
The error stack I obtain is as follows:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: "192.168.1.40"
at redis.clients.jedis.Connection.connect(Connection.java:150)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:71)
at redis.clients.jedis.Connection.sendCommand(Connection.java:92)
at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:84)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:65)
at TestJedis.main(TestJedis.java:43)
Caused by: java.net.UnknownHostException: "192.168.1.40"
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:144)
... 5 more
The documentation of jedis class can be found here!
P.S.: If I directly pass the host address as string, it works properly (that means the host is perfectly reachable).
prop.getProperty("IP").trim()and try.