0

Im developing an app who have an EditText for users input and an ImageView that im using like a button to save the content of the EditText when the user press it.

So, my problem is that i dont know how i can save the content of the EditText in the txt file who will be save inside the internal storage. Also i need to load the content of this txt file inside the EditText every time that the user opens the app.

Does any one can put me in the right way to do this ? thanks.

  • follow this for writing [Make a txt file in internal storage in android ](https://stackoverflow.com/questions/24751703/make-a-txt-file-in-internal-storage-in-android) and follow this for reading [How can I read a text file from the SD card in Android? ](https://stackoverflow.com/questions/2902689/how-can-i-read-a-text-file-from-the-sd-card-in-android) – Koorosh Jul 08 '17 at 18:03
  • You can save it to external storage (Jason answer) or keep it in SharedPrefrences for just save and load – momvart Jul 09 '17 at 11:11

1 Answers1

3
using System.IO;

// build path
string path = Path.Combine((string)Android.OS.Environment.ExternalStorageDirectory, "My Folder Name", "My File Name");

// write to file
File.WriteAllText(path, MyEditControl.Text);

// read from file
string text = File.ReadAllText(path);
MyEditControl.Text = text;
Jason
  • 86,222
  • 15
  • 131
  • 146