properties - Load property file with command line arguments - Java -


what best way load property file when path property file not fixed , provided via command line arguments?

i using following code load giving me null pointer exception when run using command line arguments:

properties p = new properties();         p.load(testclass.class.getresourceasstream("path property file")); 

if (full) path via command line, jsut need provide reader or input stream path. in end, code this:

    public static void main(string[] args) {             system.out.println("reading property file " + args[0]);              // create new initial properties             properties properties = new properties();             // open reader read properties file             try (filereader in = new filereader(args[0])){                 // load properties reader                 properties.load(in);             } catch (ioexception e) {                 // handle exception                 e.printstacktrace();             }              // print out read             enumeration<?> propertynames = properties.propertynames();             while(propertynames.hasmoreelements()) {                 string name = propertynames.nextelement().tostring();                 system.out.println(name + ": " + properties.getproperty(name));             }         } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -