2

I am trying to add data to a text file in android using the code below but it only overwrites the data with one line of data.

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");
    }
}
Evin1_
  • 12,292
  • 9
  • 45
  • 47
Amir
  • 1,667
  • 3
  • 23
  • 42

1 Answers1

4

The FileOutputStream constructor allows to specify whether it should append to an already existing file or not:

new FileOutputStream(file, true);

will create a stream that appends to the given file.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38