package demo1; import java.io.InputStream; import java.util.Properties; import java.util.Set; public class propertiesDemo { /* *用类名.class.getClassLoader().getResourceAsStream(文件名);来获得bin目录下的指定文件输入流 *在eclipse中将properties新建到src中会自动复制到bin目录,这样在交付软件的时候就不用在手动复制配置文件或修改代码了 */ public static void main(String[] args) throws Exception { Properties pro = new Properties(); InputStream in = propertiesDemo.class.getClassLoader().getResourceAsStream("db.properties"); pro.load(in); Set<String> set = pro.stringPropertyNames(); for (String s : set) { System.out.println(s + "=" + pro.getProperty(s)); } } }
用 类名.class.getClassLoader().getResourceAsStream来获得bin目录下的配置文件
猜你喜欢
转载自blog.csdn.net/alexzt/article/details/80268895
今日推荐
周排行