tags:

views:

28

answers:

1

Hi All,

I am trying to create an Android application that would use a configuration file (plain text) when loading.

When testing locally (with an emulator), I place my config file in the src/ folder (ecplise) and I see it is copied and used from the bin/ folder upon project build.

My questions are:

1) Where do I need to place this file when testing on a device ? From what I understand I need the *.apk file and the config file to be both present on the device during run time.

2) If I am using eclipse to install the *.apk file can I somehow specify the config file as a dependant file and force eclipse to copy it as well ? If not do I need to manually copy the *.apk & config files to the device ?

NOTE: I am using getResourceAsStream to load the file.

Thanks,

RM

+1  A: 

Well actually there shouldn't be any problems with accessing the file in a way you do. But preferred (and recommended by Android developers) way is to place the file into /res/raw folder. Then you can access the file as application resource:

InputStream is = getResources().openRawResource(R.id.your_file_name);

Here getResources is a method of Context class, it should accessible anywhere within your activities. R.id.your_file_name is a static field generated by eclipse at the time you place your file into /res/raw folder.

Read the http://developer.android.com/intl/zh-TW/guide/topics/resources/index.html to get more about application resources at Android.

Konstantin Burov
for some reason getResources is not available to me. what import or context do i need to call it in ?
Roman M
You have to obtain an instance of Context, usually that is instance of Activity. Try to post more code if you want more precise answer.
Konstantin Burov