Java Properties Load loadProperties()

Here you can find the source of loadProperties()

Description

Private methods

License

Apache License

Declaration

private static void loadProperties() throws FileNotFoundException,
        IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.FileNotFoundException;

import java.io.FileInputStream;
import java.io.File;
import java.util.Properties;
import java.util.Enumeration;

public class Main {
    private static Properties m_properties = new Properties();
    private static String m_propFilePath = new String("~");
    private static String m_propFileName = new String("~");

    /********************************************************************************
     **  Private methods//from   w  ww  .j a v  a2s . com
     *********************************************************************************/
    private static void loadProperties() throws FileNotFoundException,
            IOException {
        //refresh properties
        m_properties = new Properties();
        try {
            loadProperties(m_properties, new File(m_propFilePath,
                    m_propFileName));
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
    }

    /********************************************************************************
     **  Read from the given file and fill keys in the given property hashtable
     *********************************************************************************/
    private static void loadProperties(Properties theProperties,
            File theFile) throws FileNotFoundException, IOException {
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(theFile);
        } catch (FileNotFoundException e) {
            throw e;
        }
        try {
            theProperties.load(stream);
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                if (stream != null)
                    stream.close(); // Make sure the stream is closed promptly...
            } catch (IOException e) {
                // do nothing...
            }
        }
        // Remove any leading/trailing blanks from the property values
        Enumeration e = theProperties.propertyNames();
        while (e.hasMoreElements()) {
            Object o = e.nextElement();
            String key = (String) o;
            String val = theProperties.getProperty(key);
            String trimmedVal = val.trim();
            if (!val.equals(trimmedVal)) {
                theProperties.put(key, trimmedVal);
            }
        }
    }
}

Related

  1. loadProperties()
  2. loadProperties()
  3. loadProperties()
  4. loadProperties()
  5. loadProperties()
  6. loadProperties()
  7. loadProperties()
  8. loadProperties()
  9. loadProperties(ByteSource is)