Java Properties Load from File load(Map map, String fileName)

Here you can find the source of load(Map map, String fileName)

Description

load

License

Open Source License

Parameter

Parameter Description
map a parameter
fileName a parameter

Declaration

public static void load(Map<String, String> map, String fileName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2012 by Min Cai (min.cai.china@gmail.com).
 *
 * This file is part of the PickaPack library.
 *
 * PickaPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.//from  w ww . java2s .  co  m
 *
 * PickaPack is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PickaPack. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.io.*;
import java.util.Map;
import java.util.Properties;

public class Main {
    /**
     *
     * @param map
     * @param fileName
     */
    public static void load(Map<String, String> map, String fileName) {
        if (new File(fileName).exists()) {
            try {
                load(map, new FileInputStream(fileName));
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     *
     * @param map
     * @param in
     */
    public static void load(Map<String, String> map, InputStream in) {
        try {
            Properties prop = new Properties();

            prop.load(in);

            for (Object key : prop.keySet()) {
                map.put(key.toString(), prop.get(key).toString());
            }

            in.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. load(InputStream in)
  2. load(InputStream input)
  3. load(InputStream inputStream)
  4. load(InputStream is)
  5. load(InputStream stream)
  6. load(Properties properties, String fileName)
  7. load(Properties props, Collection filters, File basedir)
  8. load(Properties props, File f)
  9. load(Properties props, File file)