我在同一文件夹conf中加载发出加载属性文件
test.xml and test.properties
时遇到问题。
我在dist文件夹里面有一个myProject.jar,在conf文件夹里面有一个 test.xml和test.properties。
要加载xml,我使用的是
document = reader.read(new File("../conf/test.xml"));//its working
但是我在加载属性文件时遇到问题, 我使用的是
Class_name.class.getResourceAsStream("../conf/test.properties"),
getResourceAsStream("conf/test.properties"),
getResourceAsStream("/test.properties"),
getResourceAsStream("test.properties"),
没有什么能用于属性文件。
任何帮助表示赞赏。
尝试把CONF在classpath中,只是做的getResourceAsStream( “test.properties”) – Todd 2011-06-09 17:02:38
同意;你需要决定你想如何定位文件。您正在使用的File构造函数是基于当前工作目录的文件系统的完整路径名或相对路径名。 #getResourceAsStream将在类路径中找到一个文件 - 正如Todd所说的,您需要在类路径中包含'conf'目录才能访问它。根据你想装运jar的方式(带或不带配置属性文件)应该给你一些提示,以便选择。 – 2011-06-09 17:12:14