我“V创建了一个项目,上面写着一些从配置的.properties文件如何读或写的.properties文件以外的JAR文件
public class PreferenceManager {
private int refreshTime;
private String[] filters;
Properties properties ;
public PreferenceManager() throws FileNotFoundException, IOException
{
properties = new Properties();
properties.load(ClassLoader.getSystemResourceAsStream ("preferences.properties"));
}
public void save() throws IOException, URISyntaxException
{
properties.setProperty("REFRESH_TIME", String.valueOf(refreshTime));
String filtersStr = "";
if(filters!= null){
for(String str : filters)
{
if((str == null)||(str.isEmpty())) continue;
filtersStr+= str.toUpperCase()+",";
}
}
properties.setProperty("FILTERS", filtersStr);
URI uri = ClassLoader.getSystemResource("preferences.properties").toURI();
File f = new File(uri);
properties.store(new FileOutputStream(f), null);
}
}
和每一件事情是确定的。现在我需要创建一个JAR文件。我需要知道如何使这个JAR文件从包含它的文件夹中读取这个属性文件,因为当属性文件在JAR中时,我可以读取它,但是我可以在其上写入(例外:URI不是hirarchal)
所以我需要你的帮助。
感谢
我遇到了同样的问题。我无法弄清楚。我玩过一个名为one-jar的项目,但它不支持非jar资源加载。最终,我崩溃了,现在我在.jar之外即时生成属性文件。 – djangofan