Is it possible to create and remove .properties
files from Android
, by the application itself?
Ex: after creating an annotation it creates a .properties
file with the name of that annotation!
Is it possible to create and remove .properties
files from Android
, by the application itself?
Ex: after creating an annotation it creates a .properties
file with the name of that annotation!
Can not create files from the application. You can however interact with an existing file. For this purpose you should:
Create in your project, in the desired place the file that you will use from the application.
After the file you created, you can use a function like the one below to save data in it:
public void CreatePropertiesFile(Context context) {
Properties prop = new Properties();
String propertiesPath = context.getFilesDir().getPath().toString() + "/app.properties";
try {
FileOutputStream out = new FileOutputStream(propertiesPath);
prop.setProperty("HomeVersion", "0");
prop.setProperty("DatePlaySquare", "0");
prop.setProperty("CustomerID", "0");
prop.setProperty("DeviceToken", "0");
prop.setProperty("CurrentVersionMobile", "0");
prop.setProperty("Domain", "Megazy");
prop.setProperty("DownloadNewVersion","0");
prop.store(out, null);
out.close();
} catch (IOException e) {
System.err.println("Failed to open app.properties file");
e.printStackTrace();
}
}
You should adapt the function to your needs, but you already have an idea of how you can perform the operation.
This is just an example taken from this answer in SOEN by using @ user3113670.
Another good example can be found in this answer also in SOEN by the user @Javanator.
On Android, when we talk about saving data, we're almost always talking about Data Storage more specifically Shared Preferences . There is a very good tutorial on this:
Credits of this information for the user @Rajesh in this answer in the SOEN that evidenced the links to the documentation and tutorial.