Read a properties file from /assets. - Android App

Android examples for App:Assets File

Description

Read a properties file from /assets.

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;
import android.content.res.Resources;

import android.util.Log;

public class Main {
    /** Read a properties file from /assets.  Returns null if it does not exist. */
    public static Properties getProperties(String name, Context context) {
        Resources resources = context.getResources();
        AssetManager assetManager = resources.getAssets();

        // Read from the /assets directory
        try {/*from  ww  w  .  j  a v a 2  s.  c o m*/
            InputStream inputStream = assetManager.open(name);
            Properties properties = new Properties();
            properties.load(inputStream);
            return properties;
        } catch (IOException e) {
            Log.i("ChatSecure", "no chatsecure.properties available");
            return null;
        }
    }
}

Related Tutorials