我「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