get Boolean from Properties - Android java.util

Android examples for java.util:Properties

Description

get Boolean from Properties

Demo Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import android.content.Context;
import android.content.res.AssetManager;

public class Main {
    private static Properties properties;

    private static boolean getBoolean(Context context, String key,
            boolean defaultValue) {
        if (properties == null) {
            try {
                loadProperties(context);
            } catch (IOException e) {
                e.printStackTrace();//from   ww w. j ava2s  .co  m
                return defaultValue;
            }
            if (properties == null) {
                return defaultValue;
            }
        }
        if (!properties.containsKey(key)) {
            return defaultValue;
        }
        return Boolean.parseBoolean(properties.getProperty(key));
    }

    private static void loadProperties(Context context) throws IOException {
        AssetManager assetManager = context.getResources().getAssets();
        InputStream inputStream = assetManager
                .open("AcceleratedAccounting.properties");
        properties = new Properties();
        properties.load(inputStream);
    }
}

Related Tutorials