Write in .properties file in android

I am making an application with Android 2.2, I created the config.properties file in the resource folder, I am trying to change the properties using the following code:

AssetManager am = this.getResources().getAssets(); Properties pp = new Properties(); InputStream isConfig = am.open("config.properties",Context.MODE_PRIVATE); pp.load(isConfig); pp.setProperty("SHOP_URL", "NEW_SHOP_URL");//This key exists try { pp.store(new FileOutputStream("config.properties"), null); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } 

When starting the application, execute this error: java.io.FileNoFoundException: read-only file system.

I am trying to add permissions to solve this error, but I do not know what to add.

thanks for the help

+4
source share
1 answer

The problem is the file path. try using

 try { pp.store(getAssets().openFd("config.properties").createOutputStream(), null); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } 

this should fix the path problem.

+3
source

All Articles