Java Properties Load from File loadProperties(String fileName, Properties properties)

Here you can find the source of loadProperties(String fileName, Properties properties)

Description

load Properties

License

Open Source License

Declaration

static public void loadProperties(String fileName, Properties properties) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.util.Properties;

public class Main {
    private static String fUserHome = System.getProperty("user.home");
    private static char fFileSeparator = System.getProperty("file.separator").charAt(0);
    private static char fLastCharOfDirectory = fUserHome.charAt(fUserHome.length() - 1);

    static public void loadProperties(String fileName, Properties properties) {
        try {//from   w  ww.j  a v a 2  s  .  c om
            FileInputStream fis = new FileInputStream(makeFullPathname(fileName));
            BufferedInputStream bis = new BufferedInputStream(fis);
            properties.load(bis);
            bis.close();
            fis.close();
        } catch (FileNotFoundException e) {
            // Do nothing. Data file will be created eventaully.
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static public String makeFullPathname(String fileName) {
        if (fLastCharOfDirectory == fFileSeparator)
            return fUserHome + fileName;
        else
            return fUserHome + fFileSeparator + fileName;
    }
}

Related

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