PropertiesConfiguration.java
沒有close()
方法。還有什麼需要做的來釋放文件嗎?我希望在生產中使用它之前確定。我查看了代碼,但沒有看到任何內容。我不完全確定PropertiesConfiguration.setProperty()
如何在沒有打開連接的情況下工作,然後該連接將不得不關閉。Apache Commons Configuration - PropertiesConfiguration closed
0
A
回答
1
在org.apache.commons.configuration.PropertiesConfiguration
當在PropertiesConfiguration
實例中加載屬性時,輸入(流,路徑,url等等)當然是關閉的。
您可以在void load(URL url)
方法org.apache.commons.configuration.AbstractFileConfiguration
中確認。
下面是如何調用此方法:
1)PropertiesConfiguration
構造函數被調用:
public PropertiesConfiguration(File file) throws ConfigurationException
2),其調用其超級構造:
public AbstractFileConfiguration(File file) throws ConfigurationException
{
this();
// set the file and update the url, the base path and the file name
setFile(file);
// load the file
if (file.exists())
{
load(); // method which interest you
}
}
3),其調用load()
:
public void load() throws ConfigurationException
{
if (sourceURL != null)
{
load(sourceURL);
}
else
{
load(getFileName());
}
}
4)調用load(String fileName)
:
public void load(String fileName) throws ConfigurationException
{
try
{
URL url = ConfigurationUtils.locate(this.fileSystem, basePath, fileName);
if (url == null)
{
throw new ConfigurationException("Cannot locate configuration source " + fileName);
}
load(url);
}
catch (ConfigurationException e)
{
throw e;
}
catch (Exception e)
{
throw new ConfigurationException("Unable to load the configuration file " + fileName, e);
}
}
5)調用load(URL url)
public void load(URL url) throws ConfigurationException
{
if (sourceURL == null)
{
if (StringUtils.isEmpty(getBasePath()))
{
// ensure that we have a valid base path
setBasePath(url.toString());
}
sourceURL = url;
}
InputStream in = null;
try
{
in = fileSystem.getInputStream(url);
load(in);
}
catch (ConfigurationException e)
{
throw e;
}
catch (Exception e)
{
throw new ConfigurationException("Unable to load the configuration from the URL " + url, e);
}
finally
{
// close the input stream
try
{
if (in != null)
{
in.close();
}
}
catch (IOException e)
{
getLogger().warn("Could not close input stream", e);
}
}
}
而在finally
語句中,可以看到,InputStream爲在任何情況下關閉。
+0
謝謝@davidxxx。我想我不相信我所看到的。 – pyetti
相關問題
- 1. Java,Apache Commons Configuration XML屬性
- 2. 任何Apache Commons-Configuration替換/競爭者?
- 3. 屬性文件沒有反映使用Apache Commons Configuration也
- 4. Commons configuration - JNDIConfiguration - 如何?
- 5. commons configuration:逗號和多鍵問題
- 6. apache-commons-config PropertiesConfiguration:最後一個屬性丟失後的註釋
- 7. 將commons-configuration添加到m2eclipse的問題
- 8. Hbase異常org/apache/commons/configuration /找不到配置
- 9. 如何使Commons Configuration的setListDelimiter有效?
- 10. apache commons configuration2:ConfigurationEvent沒有爲ReloadingFileBasedConfigurationBuilder生成
- 11. Apache Commons JCI ReloadingClassLoader
- 12. sun.misc.BASE64到apache commons
- 13. Apache commons csv
- 14. Apache Commons FTPClient Loggin
- 15. apache commons lang StrTokenizer
- 16. 無法在maven web項目中使用Commons Configuration讀取config.properties
- 17. Apache Karaf和Apache Commons Bundles
- 18. 使用Apache Commons Configuration在屬性文件中使用值列表執行變量插值(即$ {variable})
- 19. java:Preferences API與Apache Commons配置
- 20. Apache commons untar:IllegalArgumentException與getNextTarEntry
- 21. java.lang.NoClassDefFoundError:org/apache/commons/lang3/ObjectUtils
- 22. 使用Apache commons FileUpload
- 23. Java Apache Commons用戶
- 24. Apache Commons IO in .Net
- 25. apache commons | pool或pool2
- 26. java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory
- 27. Apache commons + log4j日誌記錄
- 28. Apache POI 3.15 org/apache/commons/collections4/ListValuedMap missing
- 29. 用Apache Commons配置讀取配置
- 30. Apache Commons Logging - New Line Charachters
你在說什麼? – shmosel
JRE中沒有'PropertiesConfiguration'類。如果你從其他地方得到它,你需要解釋。 – chrylis
我假設他在談論Apache Commons Configuration中的'PropertiesConfiguration'類。如果您不知道如何使用「加載」方法,則無法明確回答此問題,但作爲一般經驗法則,如果您打開資源,_you_需要關閉它。如果數千字庫使用的庫打開它,您可以放心,它正在被正確清理。 – rmlan