Java ClassLoader load(final String filename)

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

Description

Load a properties file from the classpath

License

Open Source License

Parameter

Parameter Description
filename a parameter

Exception

Parameter Description
IOException an exception

Return

Properties

Declaration

public static Properties load(final String filename) 

Method Source Code

//package com.java2s;
/**//from   w w w.  j  a v  a  2  s . c  o m
   * Copyright (C) 2010 Swiss Library for the Blind, Visually Impaired and Print Disabled
   *
   * This file is part of dtbook-preptools.
   *    
   * dtbook-preptools is free software: you can redistribute it
   * and/or modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation, either
   * version 3 of the License, or (at your option) any later version.
   *    
   * This program 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
   * Lesser General Public License for more details.
   *    
   * You should have received a copy of the GNU Lesser General Public
   * License along with this program. If not, see
   * <http://www.gnu.org/licenses/>.
   */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.net.URL;
import java.util.Properties;

public class Main {
    /**
     * Load a properties file from the classpath
     * 
     * @param filename
     * @return Properties
     * @throws IOException
     */
    public static Properties load(final String filename) {
        final Properties props = new Properties();
        final URL url = ClassLoader.getSystemResource(filename);
        if (url != null) {
            try {
                props.load(url.openStream());
            } catch (final IOException e) {
                e.printStackTrace();
                props.put("stamp", "loading from url " + url + " for " + filename + " failed " + e);
            }
        } else {
            props.put("stamp", "url was null for " + filename);
        }
        return props;
    }

    /**
     * Load a Properties File
     * 
     * @param propsFile
     * @return Properties
     * @throws IOException
     */
    public static Properties load(final File propsFile) throws IOException {
        final Properties props = new Properties();
        final FileInputStream fis = new FileInputStream(propsFile);
        props.load(fis);
        fis.close();
        return props;
    }
}

Related

  1. hasImageFile(String name)
  2. hasLogDatePatternMatcher(final String line)
  3. isExist(String path)
  4. isVMAlive(String procId)
  5. load(File propsFile)
  6. load(String propertiesName)
  7. load(String propsName)
  8. loadAttachApi()
  9. loadCorrectedConfiguration(String configurationFilename)