Here you can find the source of load(File propertiesFile)
Parameter | Description |
---|---|
propertiesFile | properties file to be loaded |
public static Properties load(File propertiesFile)
//package com.java2s; /*/* ww w.ja v a 2s.c o m*/ * Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved. * * This program is licensed to you under the Apache License Version 2.0, * and you may not use this file except in compliance with the Apache License Version 2.0. * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. * * Unless required by applicable law or agreed to in writing, * software distributed under the Apache License Version 2.0 is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import static com.google.common.base.Preconditions.checkNotNull; public class Main { /** * Loads a properties file. If file does not exist creates a set of empty properties. * * @param propertiesFile properties file to be loaded * @return loaded properties, empty if properties file does not exist */ public static Properties load(File propertiesFile) { if (!checkNotNull(propertiesFile).exists()) { return new Properties(); } InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(propertiesFile)); Properties properties = new Properties(); if (propertiesFile.getName().endsWith(".xml")) { properties.loadFromXML(in); } else { properties.load(in); } return properties; } catch (Exception e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { throw new RuntimeException(e); } } } } }