- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
PropertiesConfiguration.java
没有 close()
方法。是否还需要执行其他操作才能释放该文件?我想在生产中使用它之前确定一下。我查看了代码,但没有看到任何内容。我不完全确定 PropertiesConfiguration.setProperty()
在不打开与文件的连接(然后必须关闭该连接)的情况下如何工作。
最佳答案
在 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) 调用其 super 构造函数:
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
中语句,您可以看到输入流在任何情况下都是关闭的。
关于java - Apache Commons 配置 - PropertiesConfiguration 已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897451/
我希望每 xx 秒重新加载我的属性文件。我的代码: ... configuration = new PropertiesConfiguration(); configuration.setFileNa
我正在使用 PropertiesConfiguration 加载和存储属性值。 如果我在属性值中使用字符“/”,它会被保存为“\/”。你能帮我保存'/'而不是'\/'吗?我在这里遗漏了什么吗? Pro
假设我有以下两个配置文件: 文件1: key1 = ${common.key1} key2 = ${common.key2} 文件2: common.key1 = value1 common.key2
背景: 我要求向用户显示的消息必须因语言和公司部门而异。因此,我不能使用开箱即用的资源包,所以我实际上是在使用 PropertiesConfiguration 文件编写我自己的资源包版本。 此外,我有
为了更新我的 .properties 文件,我使用 Apache Commons Configuration 的 PropertiesConfiguration .但是当我使用代码时: try {
我有一个带有 List 值(逗号分隔)的属性的属性文件,如何将这个属性写成多行? (逗号后的反斜杠)? 我找不到任何关于这个或至少关于将逗号转义为逗号和反斜杠的信息。 最佳答案 如果您的意思如下;这仅
我有一个 PropertiesConfiguration 对象。我可以多次调用 getInt()、getString() 等而不关心性能吗?我的意思是,它不会每次都从文件中读取或以任何其他方式降低我的
我正在尝试设置一个FileBasedConfigurationBuilder,以便我可以使用PropertiesConfiguration,但我收到一个NoClassDefFoundError。这是我
我使用 Apache 配置设置了以下配置: import org.apache.commons.configuration.Configuration; import org.apache.commo
我是新手,擅长使用grails。 在我的grails应用程序中,我必须使用apache commons以下代码编辑属性文件,而不删除该Iam的其他键值 PropertiesConfiguration
PropertiesConfiguration.java 没有 close() 方法。是否还需要执行其他操作才能释放该文件?我想在生产中使用它之前确定一下。我查看了代码,但没有看到任何内容。我不完全确
我们有一个“.properties”文件,其中一些值以 JSON 形式保存。不过,我总是被特殊字符困扰—— org.json.JSONObject 对于导致它窒息的原因并不是很详细,所以需要很长时间才
这个让我难住了。 我有这样的东西: PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setProperty("url",
我有一个返回配置对象的方法。我需要实例化一个 PropertiesConfig 对象以将其保存到磁盘。我怎样才能这样做? 最佳答案 您尝试过使用复制方法吗?这个例子对我有用: XMLConfi
我们有一个使用 .properties 来存储语言翻译的应用程序。我们尝试使用 PropertyResourceBundle 和 PropertiesConfiguration(独立)访问它们。在本地
我正在使用 PropertiesConfiguration编辑属性文件。这允许我保留评论。除了最后一个键之后的评论之外,一切正常.. 例如输入文件 # *** A comment GameCheck.
我想加载属性文件和命令行参数,然后在运行时动态配置日志记录,我以前可以这样做: Properties configuration; ... ByteArrayOutputStream os = new
我是一名优秀的程序员,十分优秀!