Java Properties to Map propertiesToMap(String propertiesAsString)

Here you can find the source of propertiesToMap(String propertiesAsString)

Description

properties To Map

License

Apache License

Declaration

public static Map<String, String> propertiesToMap(String propertiesAsString) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   w w  w .  j ava2 s  .  co m*/
 * Copyright (C) 2016 Hurence (support@hurence.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import java.io.StringReader;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

public class Main {
    public static Map<String, String> propertiesToMap(String propertiesAsString) throws IOException {
        Properties props = new Properties();
        props.load(new StringReader(propertiesAsString));
        return props.entrySet().stream()
                .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
    }
}

Related

  1. propertiesToMap(File propsFile)
  2. toMap(final Properties properties)
  3. toMap(final Properties properties)
  4. toMap(Properties properties)
  5. toMap(Properties properties)