Home » Android » java – How to load .properties file data in android studio project

java – How to load .properties file data in android studio project

Posted by: admin May 14, 2020 Leave a comment


In my current application i need to maintain one config.properties file and from this properties file i need to get the data in my java file. I have placed the properties file and ConfigUtil.java which is accessing those properties files values are in the same location. But when i am running the application it’s giving FileNotFoundException.

I am not able to get why this is not loading the properties file when both are inside the same folder.

My ConfigUtils.java code is :

public class ConfigUtil {

private Properties properties;
InputStream inputStream = null;

public Properties getUrl(){
    properties = new Properties();
    try {
        inputStream = new FileInputStream("config.properties");

    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }finally {
        if(inputStream != null){
            try {
            } catch (IOException e) {
    return properties;

and config.properties file is also in same folder
location of config.properties is :


location of ConfigUtil.java is :


How to&Answers:

Step 1

Create a .properties file in assets folder, if you don’t have assets folder please create one under main

enter image description here

enter image description here


name=User Name
age=User Age

Step 2

Create a Util.java file to read the properties file.


package javaant.com.propertiesfile;

import android.content.Context;
import android.content.res.AssetManager;

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

 * Created by Nirmal Dhara on 12-07-2015.
public class Util {
    public static String getProperty(String key,Context context) throws IOException {
        Properties properties = new Properties();;
        AssetManager assetManager = context.getAssets();
        InputStream inputStream = assetManager.open("config.properties");
        return properties.getProperty(key);


Step 3

Use variables in the properties file by calling Util.getProperty(,getApplicationContext()).


package javaant.com.propertiesfile;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import java.io.IOException;

public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {


        // read value from properties file

        TextView txtname= (TextView) findViewById(R.id.txtname);
        TextView txtage= (TextView) findViewById(R.id.txtage);
        Button btnok= (Button) findViewById(R.id.btnok);

        try {
        } catch (IOException e) {

Please download the complete code from here http://javaant.com/how-to-use-properties-file-in-android/#.VwzippN96Hs


You should either specify the full path to the file (because the root working directory is not the directory where ConfigUtil is located) :

inputStream = new FileInputStream("src/main/java/config.properties");

or use the following (which is using the directory ConfigUtil was loaded from):

inputStream = getClass().getResourceAsStream("config.properties");