Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以像C中的app.config那样在java中转换.properties文件#_Java_C#_Config Transformation - Fatal编程技术网

是否可以像C中的app.config那样在java中转换.properties文件#

是否可以像C中的app.config那样在java中转换.properties文件#,java,c#,config-transformation,Java,C#,Config Transformation,我在我们的项目中有带有调试设置的debug.properties文件。此文件位于repo中,每个teamate在调试之前都应该对此文件进行更改 在C#中进行类似生成的xml转换之前,是否可以基于一些debug.template.properties文件修改此文件?您可以使用库和以下代码: private ConfigurationProvider configureProvider() { ClassLoader classLoader = getClass().getClassLoad

我在我们的项目中有带有调试设置的
debug.properties
文件。此文件位于repo中,每个teamate在调试之前都应该对此文件进行更改

在C#中进行类似生成的xml转换之前,是否可以基于一些
debug.template.properties
文件修改此文件?

您可以使用库和以下代码:

private ConfigurationProvider configureProvider() {
    ClassLoader classLoader = getClass().getClassLoader();
    String envPath = classLoader.getResource("properties").getPath();
    Path localPropertiesFilePath = Paths.get(envPath, "local.properties");
    Path basePropertiesFilePath = Paths.get(envPath, "base.properties");

    if (!Files.exists(localPropertiesFilePath)) {
        try {
            Files.createFile(localPropertiesFilePath);
        }
        catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    ConfigFilesProvider localConfigFilesProvider =
            () -> Collections.singletonList(localPropertiesFilePath);
    ConfigFilesProvider baseConfigFilesProvider =
            () -> Collections.singletonList(basePropertiesFilePath);

    ConfigurationSource local = new FilesConfigurationSource(localConfigFilesProvider);
    ConfigurationSource base = new FilesConfigurationSource(baseConfigFilesProvider);
    // If you have 'some' property in base and local files - it takes from local
    ConfigurationSource mergedSource = new MergeConfigurationSource(base, local);

    Environment environment = new ImmutableEnvironment(envPath);

    return new ConfigurationProviderBuilder()
            .withConfigurationSource(mergedSource)
            .withEnvironment(environment)
            .build();
}