java - ClassLoader.class.getResourceAsStream is not working in my code -
the below given code returning null when loading property file. kindly go through code , suggest me changes.
constantprop = new properties(); try { // loads constants.properties file inputstream constantpropfile = classloader.class .getresourceasstream("/constantfiles/" + ".properties"); system.out.println(constantpropfile); constantprop.load(constantpropfile); } catch (filenotfoundexception e) { // todo auto-generated catch block // e.printstacktrace(); log.equals("constant property file not found"); } catch (ioexception e) { // todo auto-generated catch block // e.printstacktrace(); log.error("can't load constants.properties property file "); }
if using method getresourceasstream
describes:
the search order described in documentation {@link getresource(string)}.
an input stream reading resource, or null if resource not found
and make sure link working properly.
so if trying load property file local machine or path know, can use below code loading property files:
properties prop = new properties(); prop.load(new fileinputstream("/constantfiles/.properties"));
Comments
Post a Comment