Here you can find the source of loadConfigProperties()
Parameter | Description |
---|---|
Exception | throws, if fails |
public static void loadConfigProperties() throws Exception
//package com.java2s; /*//from ww w . j ava 2 s .c o m * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.*; import java.util.Properties; public class Main { private static Properties configProperties; /** * reads values from config property file * * @throws Exception throws, if fails */ public static void loadConfigProperties() throws Exception { Properties properties = new Properties(); InputStream inputStream = null; try { File file = new File((new File(".")).getCanonicalPath() + File.separator + "resources" + File.separator + "config.properties"); if (file.exists()) { inputStream = new FileInputStream(file); } else { String msg = "File does not exist : " + "config.properties"; System.out.println(msg); } } catch (FileNotFoundException e) { String msg = "File can not be found : " + "config.properties"; System.out.println(msg); throw new Exception(msg, e); } catch (IOException e) { String msg = "Can not create the canonical file path for given file : " + "config.properties"; System.out.println(msg); throw new Exception(msg, e); } try { if (inputStream != null) { properties.load(inputStream); } } catch (IOException e) { String msg = "Error loading properties from config.properties file"; System.out.println(msg); throw new Exception(msg, e); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ignored) { System.out.println("Error while closing input stream"); } } configProperties = properties; } }