【问题标题】:Saving the text from an EditText从 EditText 保存文本
【发布时间】:2012-02-21 01:16:32
【问题描述】:

我正在尝试保存 EditText 中的文本,我得到了它的工作,但我认为我做的不正确。当我在我的应用程序中重新打开它时很好,但是当我从设备中拉出它并在 Windows 记事本中打开它时,我失去了换行符。

...     
        try {
            BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
            buf.append(cv.getText().toString());
            buf.close();
        } catch(IOException e) {
            e.printStackTrace();
        }

保存大EditText的完整文本的正确方法是什么?

【问题讨论】:

  • Windows 使用 \r\n 作为换行符,而 Unix 使用 \n

标签: android android-edittext bufferedwriter


【解决方案1】:

你做对了 - 问题是记事本不理解 Unix line termination 约定。

在写字板中打开文件,您会看到它应该正确显示。

【讨论】:

  • 好的,谢谢!你是对的。有什么办法可以改正吗?
【解决方案2】:

尝试buf.append(cv.getText().toString().replace("\n", "\r\n"); 使换行符在 Windows 程序中可读。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多