将数据附加到Android中的文本文件

时间:2016-06-19 20:02:56

标签: android append text-files

我正在尝试使用下面的代码将数据添加到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");
    }
}

1 个答案:

答案 0 :(得分:3)

FileOutputStream构造函数允许指定它是否应附加到现有文件中:

new FileOutputStream(file, true);

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