【问题标题】:Appending data to a text file in Android在Android中将数据附加到文本文件
【发布时间】:2016-10-21 01:08:14
【问题描述】:

我正在尝试使用下面的代码将数据添加到 android 中的文本文件,但它只会用一行数据覆盖数据。

private void copyImageToMemory(File outFile , Float number) {
    try {

        BufferedOutputStream fos = new BufferedOutputStream(
                new FileOutputStream(outFile));


        PrintWriter pw = new PrintWriter(new BufferedWriter(
                new OutputStreamWriter(fos)));

        pw.append("result"+number);
        pw.close();
        maxSpeed=0;

    } catch (FileNotFoundException e) {
        Log.e(TAGFile, "FileNotFoundException");
    }
}

【问题讨论】:

标签: android append text-files


【解决方案1】:

FileOutputStream 构造函数允许指定它是否应该附加到已经存在的文件:

new FileOutputStream(file, true);

将创建一个附加到给定文件的流。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-04
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 2019-12-18
    相关资源
    最近更新 更多