when you do FileWriter fw = new FileWriter(doggy);
it opens file in write mode and deletes the previous data of file. Thats why whie reading the file it gives EOFException
because there is nothing to read in file.
If you do like this FileWriter fw = new FileWriter(doggy,true);
then there will be no error because it does not delete the previous data of file.