Write to a File Exercise
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 Exercise 2 and
add to it to write to a file. You can do this in multiple ways...
- using FileOutputStream and DataOutputStream classes
- using FileWriter and BufferedWriter classes
- using FileOutputStream and PrintStream classes
Solution 1 (using FileOutputStream and DataOutputStream)
Solution 2 (using FileWriter and BufferedWriter)
Solution 3 (using FileOutputStream and PrintStream)