Hi I need to create a file that will store some infos about my app, where should file.createNewFile() be used? I was thinking about onCreate() method in MainActivity but then it would create and override it everytime I run my app.
Asked
Active
Viewed 38 times
-2
-
post the code what you have tried refer [here](https://stackoverflow.com/a/9620718/2462531) – Shailendra Madda Nov 22 '17 at 14:49
-
`where should I use file.createNewFile()? I` Do NOT use that function to begin with. – greenapps Nov 22 '17 at 14:54
-
I'd create the file for *append*. So, if it's existing, it won't be recreated every time. Moreover, take a look at SharedPreferences. Maybe that's what you actually need. Furthermore, I'd only read/write to the file when it's strictly needed, keeping it closed most of the time. – Phantômaxx Nov 22 '17 at 15:08
2 Answers
0
You should create a manager with static methods, first you check in the manager if the files exists and put the value in a static variable, then either override the file if you need to change the values or write the file if it doesn't exist

Quentin Menini
- 160
- 1
- 1
- 12
0
onCreate() is the good place to create new file, But before creating file check that file is already exists or not. if file does not exists create one.After creating the file save that path in Shared Preference. And in onCreate(), check that file exists. If exists don't create else create the file and update the path in shared preference .Hope that helps.

Abdul Waheed
- 4,540
- 6
- 35
- 58