Inserting data "somewhere" in a sequential file would require that the entire file be rewritten. It is possible, however, to add data to the end of a file without rewriting the entire file. Adding data to the end of an existing file is called appending.
To attempt appending a file, the FileWriter class will be needed
as it can directly address appending.
FileWriter(String file, boolean append)
If append is stated as true, output will be appended to the end of the existing file contents.
FileWriter fw = new FileWriter("YourFile.txt", true);
PrintWriter pw = new PrintWriter(fw);
catch (IOException e)
The exception on FileWriter is IOException, so the catch will address this exception.
The FileNotFoundException of PrintWriter falls under the IOException.