Java Properties Load from File load(String filename)

Here you can find the source of load(String filename)

Description

load

License

Open Source License

Declaration

public static Map<String, String> load(String filename) throws IOException 

Method Source Code


//package com.java2s;
/*/*from   w w  w.j a v a2  s. c om*/
 * Copyright (c) 2008-2016, GigaSpaces Technologies, Inc. All Rights Reserved.
 *
 * 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.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import java.util.HashMap;

import java.util.Map;

import java.util.Properties;

import java.util.TreeMap;

public class Main {
    public static Map<String, String> load(InputStream in) throws IOException {

        Properties properties = new Properties();
        properties.load(in);
        return convertPropertiesToMapStringString(properties);
    }

    public static Map<String, String> load(String filename) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(new File(filename));
        try {
            return load(fileInputStream);
        } finally {
            fileInputStream.close();
        }
    }

    public static Map<String, String> convertPropertiesToMapStringString(Properties properties2) {
        Map<String, String> properties = new HashMap<String, String>();
        for (Map.Entry<Object, Object> entry : properties2.entrySet()) {
            properties.put(entry.getKey().toString(), entry.getValue().toString());
        }
        return properties;
    }

    public static String toString(Map<String, String> properties) {
        //sort and print
        return new TreeMap<String, String>(properties).toString();
    }
}

Related

  1. load(Properties props, File file)
  2. load(Properties props, String filename)
  3. load(String file)
  4. load(String file)
  5. load(String filename)
  6. load(String fileName)
  7. load(String fileName)
  8. load(String fileName)
  9. load(String filename)