File Input/Output

Simple File Input and Output of Strings

Here are a few videos on file input and output in Java. Moving forward, it will be expected that you know how to access files and read/write them.

Activities

Create programs that will:

  1. Open a file for writing in Java and print your name to the file.
  2. Download the file [lines.txt]. Write a program that will count the number of lines in the file and output it to the console (or a GUI)
  3. Download the file [census.txt] below. This contains census data for the number of people living in 1000 houses. Write the following statistics to a file named "stats.txt":
    1. Total number of people in the file.
    2. Average family size.
    3. Number of households that have 1 person living in them.
    4. Number of households that have 6 people living in them.