String Realpath = Request.getrealpath ("web-inf/classes/com/properties/devicetype.properties");
The above is the most correct way to get the path, so the properties can be placed under a COM package, or in the SRC directory.
Properties props =NewProperties (); ArrayList Al=NewArrayList (); Try{InputStream in=NewBufferedinputstream (NewFileInputStream (Realpath)); Props.load (in); Enumeration en=Props.propertynames (); while(En.hasmoreelements ()) {String key=(String) en.nextelement (); String Property=Props.getproperty (key); Al.add (property); //System.out.println (key+property); } } Catch(Exception e) {e.printstacktrace (); }
The above code can successfully read the key and value values of the properties configuration file from the specified directory and do the related processing according to the relevant business.
Welcome to follow Weibo: Http://weibo.com/cxais
Jsp+java+properties+fileinputstream file read/write, JSP page read properties file