【问题标题】:Store paths in property files在属性文件中存储路径
【发布时间】:2011-01-20 10:27:28
【问题描述】:

我有在 Linux 和 Windows 上运行的 Java 应用程序,并且应用程序取决于某些程序的路径(我需要在我的应用程序中读取两条路径,一条如果我在 Windows 上,第二条如果我在 Linux 上,我在我的代码 )。如何通过属性文件实现这一点?

【问题讨论】:

    标签: java


    【解决方案1】:

    简单地添加两个属性怎么样?

    org.example.linux.path=...
    org.example.windows.path=...
    

    并阅读您需要的属性

    String path = props.getProperty("org.example." + getOS() + ".path");
    

    编辑:顺便说一句,您可以从this question 了解不同的系统属性及其各自的值

    【讨论】:

      【解决方案2】:

      您可以阅读操作系统。由

      System.getProperty("os.name");
      

      然后有条件地读取属性文件

      【讨论】:

        【解决方案3】:

        你可以使用

        System.getProperty("os.name")
        

        【讨论】:

          【解决方案4】:

          您对每个操作系统都有一个属性文件,并根据您运行的操作系统决定加载哪一个。例如 linux.properties 将包含 Linux 路径,而 windows.properties 将包含 windows 路径。

          【讨论】:

            【解决方案5】:

            只是一个想法不一定正确。我们可以尝试拥有一个键为

            的属性吗

            DS = "\" 用于一个操作系统,并且 DS1 = "/" 用于另一个操作系统,我们根据我是在 windows 还是 mozilla 上选择它。

            我们将路径保存为

            path = "c:".DS."dir1".DS."dir2"

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-10-05
              • 2013-08-30
              • 2013-04-05
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多