get Property file from Asset - Android java.util

Android examples for java.util:Properties

Description

get Property file from Asset

Demo Code


//package com.java2s;

import java.io.InputStream;

import java.util.Properties;
import android.content.res.AssetManager;
import android.util.Log;

public class Main {
    private static Properties properties = null;

    public static String getProperty(AssetManager assetManager, String key) {
        if (properties == null) {
            loadProperties(assetManager);
        }/*  w  ww.  j  a va2  s  .  c  om*/

        return properties.getProperty(key);
    }

    public static void loadProperties(AssetManager assetManager) {
        // Read from the /assets directory
        try {
            InputStream inputStream = assetManager.open("env.conf");
            properties = new Properties();
            properties.load(inputStream);
            inputStream.close();
        } catch (Exception e) {
            Log.i("PronosChallenge", "Failed to open env.conf file");
            e.printStackTrace();
        }

    }
}

Related Tutorials