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