Q:

Write in existing .txt file

How can I write in existing .txt file? I've tried multiple approaches, I've stopped on this one:
 private void writeToFile(String data) {
    try {

        File file = new File(infoDirectory, txtName);
        FileOutputStream fOut = new FileOutputStream(file);
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(data);
        myOutWriter.close();
        fOut.close();

    }
    catch (IOException e) {
        Log.i("Debug", "File write failed: " + e.toString());
    }
}

But instead of adding string to the file, it re-writes insides.
[UPDATE]
private void writeToFile(String data) {
    try {
        File file = new File(infoDirectory, txtName);
        FileWriter append = new FileWriter(file, true);
        BufferedWriter output = new BufferedWriter(append);

        output.write(data);

    }
    catch (IOException e) {
        Log.i("Debug", "File write failed: " + e.toString());
    }
}

[WORKING CODE]
private void writeToFile(String data) {
        try {

            File file = new File(infoDirectory, txtName);
            FileOutputStream fOut = new FileOutputStream(file,true);
            OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
            myOutWriter.append(data);
            myOutWriter.close();
            fOut.close();
        }
        catch (IOException e) {
            Log.i("Debug", "File write failed: " + e.toString());
        }
    }

A:

You have to open the file in append mode, which can be achieved by using the 
FileWriter(String fileName, boolean append) constructor.
Replace this line
FileOutputStream fOut = new FileOutputStream(file);
To
FileOutputStream fOut = openFileOutput("yourfile.txt", MODE_APPEND);
Hope it helps.

