Check out example codes for "how to add to a file in java". It will help you in understanding the concepts better.

Code Example 1

File file = new File("append.txt");
FileWriter fr = new FileWriter(file, true);
BufferedWriter br = new BufferedWriter(fr);
PrintWriter pr = new PrintWriter(br);
pr.println("data");
pr.close();
br.close();
fr.close();

Learn ReactJs, React Native from akashmittal.com