Here you can find the source of loadProperties(File file)
File
.
Parameter | Description |
---|---|
file | Propertie file to load. |
Parameter | Description |
---|---|
IOException | an exception |
public static Properties loadProperties(File file) throws IOException
//package com.java2s; /* ===================================================================== * Mfg_scmUtils -/*from ww w. j a v a 2 s . c o m*/ ------------------------------------------------------------------------- Copyright (c) 1991-2013 Andre Charles Legendre <andre.legendre@kalimasystems.org> Copyright other contributors as noted in the AUTHORS file. This file is part of JSPluginManager, the Javascript pluginManager for java This 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 software 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.io.InputStream; import java.util.Iterator; import java.util.Properties; public class Main { /** * Load properties from a <code>File</code>. * * @param file * Propertie file to load. * @return The loaded Properties. * @throws IOException */ public static Properties loadProperties(File file) throws IOException { if (file.exists()) { return loadProperties(new FileInputStream(file)); } return null; } /** * Load properties from an <code>InputStream</code>. * * @param is * InputStream from which load properties. * @return The loaded Properties. * @throws IOException */ public static Properties loadProperties(InputStream is) throws IOException { Properties properties = new Properties(); try { properties.load(is); for (Iterator<Object> i = properties.keySet().iterator(); i .hasNext();) { String property = (String) i.next(); properties.setProperty(property, properties.getProperty(property).trim()); } } catch (IOException e) { // ignore throw e; } finally { try { if (is != null) { is.close(); } } catch (final IOException e) { throw e; } } return properties; } }