I am trying to write an array of string into the external storage of Android emulator. Here is my code:
private void writeToFile(String[] data) {
File workingDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/wordlist.txt");
try (BufferedWriter bw = new BufferedWriter(new FileWriter(workingDir))) {
for (String line : data) {
bw.write(line + "\n");
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
It did managed to write each of the item in string array into the text file. However, the next time when I execute this function again, it wipes all the previous existing strings in the text file and replaced them instead. Any ideas on how to keep append new strings to the end of the file?
Thanks!