【问题标题】:Writing text to file in android在android中将文本写入文件
【发布时间】:2014-05-15 11:35:32
【问题描述】:

我正在尝试将文本写入 txt.file。

myOutWriter.append

我使用这种方法,但如果我这样做,我会失去我的第一个价值观。每次我看到文本文件 有 1 条记录。我该怎么办?

【问题讨论】:

标签: android file text


【解决方案1】:

试试这个:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_APPEND);
fos.write(string.getBytes());
fos.close();

【讨论】:

    【解决方案2】:

    您应该在附加模式下初始化FileWriter

    FileWriter myOutWriter = new FileWriter(fileName, true);
    

    那么 append 应该可以无缝地工作。

    祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-17
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多