0

I have an android project and I'm using a custom .properties file, that I store in in a packet together with a class with which I can access it. While I run the programm I need to change some values of the .properties file but I can't access it as I don't know which is the Location it is stored in my device.

I thought about accessing to it by using InputStream and change the values like in java with an OutputStream, but while in InputStream there is the getResourceAsStream method in OutputStream there is not an opposite method in order to perform the action I want.

I have searched on the Internet, but the only solution I found is to move my .properties file into assets directory and get access to it using AssetsManager, which I don't want to!

I'm a newbie in android so any help will be welcomed !!

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
gimbo
  • 67
  • 1
  • 18

1 Answers1

0

You could put it in a directory in the external storage and then read it like a java.io.File:

File myProperties = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "myDir/myPorperties.properties");

obviously you could put the default properties file in assets and copy from asset to the external storage at the first app's run.

NB: you need this permissions in manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73
  • I want to read it from where it is ! Secondly I want also to write in it ! – gimbo Feb 25 '14 at 18:09
  • why you can't move the file from where it is? – Manuel Spigolon Feb 26 '14 at 08:13
  • If moved it I should change the whole project ! I'm just trying to avoid it ! – gimbo Feb 26 '14 at 09:04
  • 1
    at least you could use your private directory: /data/data//files/ where only your app have r/w permissions. But you cannot modify a prop file inside the src directory because the content in src folder are stored in a [.dex](http://stackoverflow.com/questions/7750448/dex-file-in-android) file inside the apk. In other words you are trying to modify a file inside a running-jar and this is not possible. – Manuel Spigolon Feb 26 '14 at 09:52