Gets properties from Assets - Android App

Android examples for App:Assets

Description

Gets properties from Assets

Demo Code


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

public class Main {
    /**//from w  w w.j  ava2 s.c  o  m
     * Gets properties from Assets
     *
     * @param name    Properties file
     * @param context Context
     * @return Properties
     */
    public static Properties getProperties(String name, Context context) {
        Resources resources = context.getResources();
        AssetManager assetManager = resources.getAssets();
        Properties properties = null;

        // Read from the /assets directory
        try {
            InputStream inputStream = assetManager.open(name);
            properties = new Properties();
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }
}

Related Tutorials