[英]Getting the used file name from a Properties instance
An instance of java.util.Properties
is passed to me which has been created using: 一个
java.util.Properties
实例被传递给我,它是使用以下方法创建的:
[...]
properties = new java.util.Properties();
try {
properties.load(
AutoProperties.class.getClassLoader().getResourceAsStream(propertyFile)
);
}
[...]
I was wondering how I could retrieve the file name ( propertyFile
above) from the properties
instance? 我想知道如何从
properties
实例检索文件名(上面的propertyFile
)? I had a glance at the API and couldn't see any easy way to do it. 我看了一眼API,却看不到任何简单的方法。
The file name (or path name in this case) is not stored in the Properties
instance. 文件名(在这种情况下为路径名)未存储在
Properties
实例中。 In fact, you haven't even passed the name to the instance. 实际上,您甚至没有将名称传递给实例。
You can't. 你不能 It's not saved in the
Properties
object. 它没有保存在
Properties
对象中。
You cannot get this information, as a Properties
object is not necessarily linked to a File... 您无法获取此信息,因为
Properties
对象不一定链接到File ...
Indeed, you can populate the Properties
in several ways: 实际上,您可以通过以下几种方式填充
Properties
:
put()
method from the Hashtable class). put()
方法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.