CS3340:  Intro OOP and Design

Write to a File Exercise

due

Create a file called data.txt that contains the Names and ages of 3 people. It looks like:
Name 1
Age 1
Name 2
Age 2
Name 3
Age 3


Write the java code that reads in the data and stores it in a Names and Ages arrays and finally prints out the information in reverse order to a file called reverse.txt. Hint: Use the program from previous Exercise solution and add to it to write to a file. You can do this in multiple ways...
  1. using FileOutputStream and DataOutputStream classes
  2. using FileWriter and BufferedWriter classes
  3. using FileOutputStream and PrintStream classes

Solution 1 (using FileOutputStream and DataOutputStream)

Solution 2 (using FileWriter and BufferedWriter)

Solution 3 (using FileOutputStream and PrintStream)
© Lynne Grewe