- First flush the steam(writer) and close them.
You can not have two files with same name. You are trying to rename the temp file with input file. You need to delete input file and then rename it to that.
reader.close(); writer.flush(); writer.close(); inputFile.delete();
Add these lines before rename and it will work