【问题标题】:Getting the used file name from a Properties instance从 Properties 实例中获取使用的文件名
【发布时间】:2009-09-07 11:32:41
【问题描述】:

java.util.Properties 的一个实例被传递给我,它是使用以下方法创建的:

[...]
properties = new java.util.Properties();

try {
  properties.load(
    AutoProperties.class.getClassLoader().getResourceAsStream(propertyFile)
  );
}
[...]

我想知道如何从properties 实例中检索文件名(上面的propertyFile)?我看了一眼 API,找不到任何简单的方法。

【问题讨论】:

    标签: java properties filenames


    【解决方案1】:

    文件名(或本例中的路径名)未存储在Properties 实例中。事实上,您甚至还没有将名称传递给实例。

    【讨论】:

      【解决方案2】:

      你不能。它没有保存在Properties 对象中。

      【讨论】:

        【解决方案3】:

        您无法获取此信息,因为 Properties 对象不一定链接到文件...

        确实,您可以通过多种方式填充Properties

        • 加载属性文件(如您在示例中所做的那样)。
        • 直接填充此对象(使用 Hashtable 类中的 put() 方法)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-19
          • 2018-07-26
          • 1970-01-01
          • 2011-01-14
          • 2013-08-22
          • 1970-01-01
          • 2014-09-29
          • 1970-01-01
          相关资源
          最近更新 更多