Check out example codes for "rewrite file java". It will help you in understanding the concepts better.

Code Example 1

Writer fileWriter = new FileWriter("c:\\data\\output.txt", true);  //appends to file

Writer fileWriter = new FileWriter("c:\\data\\output.txt", false); //overwrites file

Learn ReactJs, React Native from akashmittal.com