Java URL Load loadProperties(final URL url)

Here you can find the source of loadProperties(final URL url)

Description

Loads a property file from given URL.

License

Open Source License

Parameter

Parameter Description
url URL to load properties from. Must not be <code>null</code>.

Exception

Parameter Description
IOException Reading error.

Return

Loaded properties.

Declaration

public static Properties loadProperties(final URL url) throws IOException 

Method Source Code

//package com.java2s;
/* This file is part of the project "Hilbert II" - http://www.qedeq.org
 *
 * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
 *
 * "Hilbert II" 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 2 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 General Public License for more details.
 *//* ww w  . j  a va  2  s .c o  m*/

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

import java.io.OutputStream;

import java.io.Reader;

import java.io.Writer;
import java.net.URL;

import java.util.Properties;

public class Main {
    /**
     * Loads a property file from given URL.
     *
     * @param   url     URL to load properties from. Must not be <code>null</code>.
     * @return  Loaded properties.
     * @throws  IOException             Reading error.
     */
    public static Properties loadProperties(final URL url) throws IOException {
        Properties newprops = new Properties();
        InputStream in = null;
        try {
            in = url.openStream();
            newprops.load(in);
        } finally {
            close(in);
        }
        return newprops;
    }

    /**
     * Closes input stream without exception.
     *
     * @param   in  Input stream, maybe <code>null</code>.
     */
    public static void close(final InputStream in) {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }

    /**
     * Closes writer without exception.
     *
     * @param   writer  Writer, maybe <code>null</code>.
     */
    public static void close(final Writer writer) {
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }

    /**
     * Closes out stream without exception.
     *
     * @param   out Output stream, maybe <code>null</code>.
     */
    public static void close(final OutputStream out) {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }

    /**
     * Closes input reader without exception.
     *
     * @param   reader  Reader, maybe <code>null</code>.
     */
    public static void close(final Reader reader) {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }
}

Related

  1. loadFully(URL url)
  2. loadFully(URL url)
  3. loadImplementations(URL url, ClassLoader loader)
  4. loadManifest(URL url)
  5. loadObject(URL url)
  6. loadProperties(Properties p, URL url)
  7. loadProperties(URL url)
  8. loadProperties(URL url)
  9. loadPropertiesFromFileOrURL(String propertiesFile)