Java Properties Load from File load(Class type, String resource, Properties map)

Here you can find the source of load(Class type, String resource, Properties map)

Description

load

License

Open Source License

Declaration

public static void load(Class type, String resource, Properties map) throws IOException 

Method Source Code


//package com.java2s;

import java.io.IOException;
import java.io.InputStream;

import java.util.Properties;
import java.util.Set;

public class Main {
    public static void load(Class type, String resource, Properties map) throws IOException {
        load(type, resource, map, true);
    }/*  www .j  a  va2s  . co  m*/

    public static void load(Class type, String resource, Properties map, boolean trim) throws IOException {
        InputStream inputStream = type.getResourceAsStream(resource);

        if (inputStream == null)
            throw new IllegalArgumentException(
                    "unable to load resource: " + resource + ", from: " + type.getPackage().getName());

        map.load(inputStream);
        inputStream.close();

        if (!trim)
            return;

        Set<String> names = map.stringPropertyNames();

        for (String name : names) {
            String value = map.getProperty(name);

            if (value != null)
                value = value.trim();

            map.remove(name);
            map.setProperty(name.trim(), value);
        }
    }
}

Related

  1. load(boolean loadAsResourceBundle, String name, ClassLoader loader)
  2. load(Class cls)
  3. load(File f)
  4. load(File file)
  5. load(File file)