How to handle file Input and Output?