【问题标题】:How can I make use of properties file to get location paths of input file in below scenario? [duplicate]在以下情况下,如何利用属性文件获取输入文件的位置路径? [复制]
【发布时间】:2016-08-17 03:12:58
【问题描述】:

我想在以下情况下使用属性文件获取文件位置路径。

FileInputStream file = 
 new FileInputStream(new File("D:\\Source folder\\sourcefile.xlsx"));

FileOutputStream outputStream = 
 new FileOutputStream("D:\\Destination folder\\destfile.xlsx")

注意:我会将属性文件放在用户可以编辑的 jar 文件之外。

提前致谢!!

【问题讨论】:

    标签: java properties


    【解决方案1】:

    看看 Java SE 7 中的 ResourceBundle 类https://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.html

    你应该能够做出类似的陈述

    destinationpath = D:\Destination folder\destfile.xlsx

    在您放置在 Server Start 类路径中的 .properties 文件中,并通过简单地指定类路径中的位置来加载它们。

    例如,如果您将“application.properties”文件放在 WEB-INF/classes/resources 中,则可以这样访问该属性:

    ResourceBundle resourceBundle = ResourceBundle.getBundle("resources.application");
    String destination = resourceBundle.getString("destinationpath")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多