Java Properties Load from File loadProperties(String filePath)

Here you can find the source of loadProperties(String filePath)

Description

load Properties

License

Apache License

Declaration

protected static Properties loadProperties(String filePath) 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import java.util.Properties;

public class Main {
    protected static Properties loadProperties(String filePath) {
        File file = new File(filePath);

        if (!file.exists()) {
            try {
                file.createNewFile();/*from   w w w. ja v  a2  s.c om*/
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }

        return loadProperties(file);
    }

    /**
     * Do load properties.
     *
     * @param file the file
     * @return the properties
     */
    public static Properties loadProperties(File file) {
        Properties props = new Properties();
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            props.load(fis);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }

        return props;
    }
}

Related

  1. loadProperties(String filename)
  2. loadProperties(String fileName)
  3. loadProperties(String fileName, boolean systemOverride)
  4. loadProperties(String fileName, Properties properties)
  5. loadProperties(String filePath)
  6. loadProperties(String path)
  7. loadProperties(String path, Class caller)
  8. loadProperties(String path, Properties defaults)
  9. loadProperties(String propertiesFile)