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. 使用apache commons-configuration PropertiesConfiguration配置java.util.logging?
- 2. Java,Apache Commons Configuration XML屬性
- 3. 任何Apache Commons-Configuration替換/競爭者?
- 4. 屬性文件沒有反映使用Apache Commons Configuration也
- 5. apache-commons-config PropertiesConfiguration:最後一個屬性丟失後的註釋
- 6. commons configuration:逗號和多鍵問題
- 7. Commons configuration - JNDIConfiguration - 如何?
- 8. Apache Commons配置文件導入文件
- 9. 將commons-configuration添加到m2eclipse的問題
- 10. Hbase異常org/apache/commons/configuration /找不到配置
- 11. 如何使Commons Configuration的setListDelimiter有效?
- 12. apache commons configuration2:ConfigurationEvent沒有爲ReloadingFileBasedConfigurationBuilder生成
- 13. sun.misc.BASE64到apache commons
- 14. apache commons lang StrTokenizer
- 15. Apache Commons JCI ReloadingClassLoader
- 16. Apache commons csv
- 17. javax.naming.NoInitialContextException Apache Commons api
- 18. Apache Commons FTPClient Loggin
- 19. 無法在maven web項目中使用Commons Configuration讀取config.properties
- 20. Apache Karaf和Apache Commons Bundles
- 21. 使用Apache Commons Configuration在屬性文件中使用值列表執行變量插值(即$ {variable})
- 22. java:Preferences API與Apache Commons配置
- 23. apache commons | pool或pool2
- 24. java.lang.NoClassDefFoundError:org/apache/commons/lang3/ObjectUtils
- 25. Apache commons untar:IllegalArgumentException與getNextTarEntry
- 26. Apache Commons FTP問題
- 27. Apache commons Fileupload vs Tomcat.util.http.fileupload
- 28. java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory
- 29. Apache Commons Validator和JUnit
- 30. 使用Apache commons FileUpload
你在說什麼? – shmosel
JRE中沒有'PropertiesConfiguration'類。如果你從其他地方得到它,你需要解釋。 – chrylis
我假設他在談論Apache Commons Configuration中的'PropertiesConfiguration'類。如果您不知道如何使用「加載」方法,則無法明確回答此問題,但作爲一般經驗法則,如果您打開資源,_you_需要關閉它。如果數千字庫使用的庫打開它,您可以放心,它正在被正確清理。 – rmlan