***.jar
my
classes
API.class
META-INF
***.properties另外我也式过直接放在jar下面
***.jar
my
classes
API.class
***.properties也不行eclipse 是这样的
myproject
src
my
classes
API.java( 里面调用 new FileInputStream("./***.properties");)
Test.java
***.properties
这样的Test.java是可以运行的
my
classes
API.class
META-INF
***.properties另外我也式过直接放在jar下面
***.jar
my
classes
API.class
***.properties也不行eclipse 是这样的
myproject
src
my
classes
API.java( 里面调用 new FileInputStream("./***.properties");)
Test.java
***.properties
这样的Test.java是可以运行的
properties文件只是我自己用,不是给用户用的。
放在根目录下也式过了,也不行
****.jar
****.pro....或者xml
这样也方便用户修改,不过你要是想为了保密你就将文件的内容加一下密就行了。
还没有看到jar里面包含配置文件的
这个properties是我自己内部程序里为了结果清楚一点用的,和调用的我api的用户无关。所以应该是在jar理的,大概例子如下 public void api()
{
loadParameterFromFile("***.properties") ;
System.out.print("test"+properties.getProperty("name"));
} static void loadParameterFromFile(String uri) {
properties = new Properties();
FileInputStream propertiesFileInputStream = null;
try {
propertiesFileInputStream = new FileInputStream(uri);
properties.load(propertiesFileInputStream);
if (logger.isInfoEnabled()) {
logger.debug("Properties-File '" + uri + "' loaded.");
}
} catch (java.io.FileNotFoundException e) {
propertiesFileInputStream = null; logger.error("Properties-File '" + uri + "' not found."); // e.printStackTrace();
} catch (java.io.IOException e) {
propertiesFileInputStream = null; logger.error("Properties-File '" + uri + "' can not be read."); e.printStackTrace();
} finally {
if (propertiesFileInputStream != null) {
try {
propertiesFileInputStream.close();
} catch (java.io.IOException e) {
}
propertiesFileInputStream = null;
}
}
}
iniFileP.load(new FileInputStream (strPath));//text是包名,把文件放在根目录下(跟类在一起,也可以建一个INI目录,然后带上目录)就行了,如下:
String strPath = ClassLoader.getSystemResource ("test/ini/iniTest.ini").toString ().substring (6);
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/packagename/*.properties"));
如果楼主搞定了请通知一声
刚开始因为这应该是个很简单的问题
假如用户用xml定义个东西,dtd应该在程序内部定义,这样的dtd不是应该由jar一起提供?要不然程序怎么验证xml的正确行,或者还有很多别的情况都要读取jar里的文件阿。jdk自带的dt.jar里
javax/swing/beaninfo/images/里面的图片不是都是里面那个class调用的吗。怎么可能文件打包进jar就读不到了,这个我觉得是不可能的
getResourceAsStream这个用来获取包里面的图片、txt文件等都可以正常取得的。调试一下,不用要load方法,
自己用这个this.getClass().getResourceAsStream("/packagename/*.properties")解析