【问题标题】:How to save the content of an EditText(Plain text) into a Txt File on internal storage如何将 EditText(纯文本)的内容保存到内部存储上的 Txt 文件中
【发布时间】:2017-07-09 02:03:09
【问题描述】:

我正在开发一个应用程序,它有一个用于用户输入的 EditText 和一个 ImageView,当用户按下它时,我使用一个按钮来保存 EditText 的内容。

所以,我的问题是我不知道如何将 EditText 的内容保存在将保存在内部存储中的 txt 文件中。此外,每次用户打开应用程序时,我都需要在 EditText 中加载此 txt 文件的内容。

有没有人可以让我以正确的方式做到这一点?谢谢。

【问题讨论】:

标签: android file xamarin android-edittext save


【解决方案1】:
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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2015-03-23
    相关资源
    最近更新 更多