查看文章
|
java读取properties
2007年11月06日 星期二 16:32
import java.io.InputStream; import java.util.Properties; public class TestProperties { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub TestProperties pro = new TestProperties(); System.out.println(pro.getParam("p.property")); } private String getParam(String file) { Properties p = new Properties(); try { InputStream in = getClass().getResourceAsStream(file); p.load(in); if (in != null) in.close(); } catch (Exception e) { System.out.println("file not found"); } finally { return p.getProperty("ip"); } } } |