String hostname from properties file: Java -


this may sound simple problem can't figure out way around this.

i have config.properties file contains 2 key values: ip address , port number. read config file extract key values in string format. however, when trying use these values, unable connect ip address retrieved config file.

the reason values read in string format , need convert them proper formats before using them. want value "192.168.1.40" stored in config file converted string host format. tried using inetaddress gives error. contents of config file are:

ip=192.168.1.40 port=9124 

the code uses these values 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 obtain follows:

exception in thread "main" redis.clients.jedis.exceptions.jedisconnectionexception: java.net.unknownhostexception: "192.168.1.40" @ redis.clients.jedis.connection.connect(connection.java:150) @ redis.clients.jedis.binaryclient.connect(binaryclient.java:71) @ redis.clients.jedis.connection.sendcommand(connection.java:92) @ redis.clients.jedis.binaryclient.ping(binaryclient.java:84) @ redis.clients.jedis.binaryjedis.ping(binaryjedis.java:65) @ testjedis.main(testjedis.java:43) caused by: java.net.unknownhostexception: "192.168.1.40" @ java.net.abstractplainsocketimpl.connect(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ redis.clients.jedis.connection.connect(connection.java:144) ... 5 more 

the documentation of jedis class can found here!

p.s.: if directly pass host address string, works (that means host reachable).

java.net.unknownhostexception: "192.168.1.40"                                ^            ^ 

imho double quotes shouldn't there exception takes string argument of hostname unknown. reason of exception can passing double quotes in hostname.

it should java.net.unknownhostexception: 192.168.12<--if host unknown

from comment

ip returned "192.168.1.40" (quotes included) when print them on screen

which means string ip="\"192.168.1.40\"" not string ip="192.168.1.40" remove double quotes configuration file.

i unable reproduce issue can use replace

string ip=prop.getproperty("ip").replace("\"","") 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -