File reading and writing should be inside a try catch block